[xhtml]

Schema Validation and the PSVI

R. Alexander Milowski

milowski at sims.berkeley.edu

#1

Schema Validation & Outcomes

#2

The PSVI

#3

Assessment Outcomes

#4

What gets validated?

#5

Processing Modes

#6

Wildcards in Content Models

#7

Schema Related Properties

#8

Element/Attribute Declaration

#9

Element/Attribute Schema Information

#10

Element/Attribute Type Information

#11

Schema Components

#12

Xerces

#13

Using Xerces' XSModel to get Schema Components

#14

Parsing and Using the PSVI in Xerces

#15

XNI Parsing Example

  1. Import the right classes:

    import org.apache.xerces.util.*;
    import org.apache.xerces.xs.*;
    import org.apache.xerces.xni.*;
    import org.apache.xerces.xni.parser.*;
    import org.apache.xerces.parsers.*;
  2. Create the parser and set the right features (much like JAXP):

    XMLParserConfiguration parser = new StandardParserConfiguration();
    parser.setFeature("http://xml.org/sax/features/validation",true);
    parser.setFeature("http://apache.org/xml/features/validation/schema",true);
    parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
    
  3. Setup the catalog:

    String [] catalogs = { "catalog.xml" };
    XMLCatalogResolver resolver = new XMLCatalogResolver(catalogs);
    parser.setEntityResolver(resolver);
    
  4. Set your document and error handlers

    parser.setDocumentHandler(new MyDocumentHandler());
    // DefaultErrorHandler is a utility class from Xerces that sends
    // errors to stderr.
    parser.setErrorHandler(new DefaultErrorHandler());
    
  5. Parse your document:

    String uri = new File("doc.xml").toURI().toString();
    XMLInputSource source = new XMLInputSource(null,uri,uri);
    parser.parse(source);

#16

XNI PSVI for Elements