How do I validate against XML schema?
In this release, schema validation has been integrated with the regular SAXParser and DOMParser classes. No special classes are required to parse documents that use a schema.
Each document that uses XML Schema grammars must specify the location of the grammars it uses by using an xsi:schemaLocation attribute if they use namespaces, and an xsi:noNamespaceSchemaLocation attribute otherwise. These are usually placed on the root / top-level element in the document, though they may occur on any element; for more details see XML Schema Part 1 section 4.3.2. Here is an example with no target namespace:
Here is an example with a target namespace. Note that it is an error to specify a different namespace than the target namespace defined in the Schema.
Review the sample file, 'data/personal.xsd' for an example of an XML Schema grammar.
How does the XML Schema processor treat entities and CDATA sections?
According to the XML Infoset the infoset items contributing to the
Does Xerces provide access to the post schema validation infoset (PSVI)?
Xerces implements the
For more information please refer to the interfaces.
What happened to the PSVI interfaces in org.apache.xerces.xni.psvi?
The PSVI interfaces which used to be part of the org.apache.xerces.xni.psvi
and org.apache.xerces.impl.xs.psvi packages were modified and have been moved
into the
How do I access PSVI via XNI?
From within an XMLDocumentHandler, one can retrieve PSVI
information while in the scope of the document handler start/end element calls:
The above code shows how to retrieve PSVI information after
elements/attributes are assessed. The other kind of information PSVI
offers is the property
org.apache.xerces.xs package.
[schema information] property is only available on the
endElement method for the validation root. When this method
is called, information about various components can be retrieved by
How do I access PSVI via DOM?
Use
the http://apache.org/xml/properties/dom/document-class-name property
to set org.apache.xerces.dom.PSVIDocumentImpl as the implementation
of the org.w3c.dom.Document interface. In the resulting DOM tree, you may cast
org.w3c.dom.Element to the
org.apache.xerces.xs.ElementPSVI and
org.w3c.dom.Attr to the
org.apache.xerces.xs.AttributePSVI.
How do I access PSVI via SAX?
The Xerces SAX parser also implements the
org.apache.xerces.xs.PSVIProvider interface.
Within the scope of the methods handling the start
(org.xml.sax.ContentHandler.startElement) and
end (org.xml.sax.ContentHandler.endElement) of an element,
applications may use the PSVIProvider to retrieve the PSVI
related to the element and its attributes.
How do I access PSVI via the JAXP 1.4 Validation API?
Like the Xerces SAX parser the implementations of javax.xml.validation.Validator
and javax.xml.validation.ValidatorHandler also implement the
org.apache.xerces.xs.PSVIProvider interface. Within the scope of the methods
handling the start (org.xml.sax.ContentHandler.startElement) and end
(org.xml.sax.ContentHandler.endElement) of an element, applications may use
the PSVIProvider to retrieve the PSVI related to the element and its attributes.
How do I parse and analyze an XML schema?
Please, refer to the Examining Grammars FAQ.
Can I parse and query XML Schema components in memory?
Yes, the XSLoader which provides methods
for loading XML Schema documents into an XSModel. The XSImplementation
interface provides a method to create an XSLoader using the
XSImplementation using the getDOMImplementation method
on the DOMImplementationRegistry object with the feature string "XS-Loader".
To create an XSLoader you need to do something like this: