This package contains an implementation of the W3C XML
Schema Language, a recommendation of the Worldwide Web Consortium
available in three parts:
XML Schema: Primer and
XML Schema: Structures and
XML Schema: Datatypes.
We consider this implementation to be complete except for the
limitations cited below. The implementation has been
extensively tested and known problem areas are set out below.
In this document we also discuss our interpretation of the
specifications where it seems to us particularly likely that
others might arrive at a different interpretation.
Please read this document before using this package.
Limitations
Length, minLength, and maxLength facets are limited to the value
2147483647. Items larger than this limit will not be validated
correctly.
Year and seconds values in date/time datatypes are limited to the
value 2147483647. Items larger than this limit will not be validated
correctly.
Problem Areas/Known Bugs
Due to changes in the specification for Decimals in
JDK1.3, not all decimals that should be invalid according
to the Schema specs may be found by the parser;
For larger values of maxOccurs, a StackOverflowError may occur.
The workaround for this problem, if your application permits it,
is to change the maxOccurs value to unbounded.
Interpretation of Areas that are Unclear or Implementation-Dependent
QName: the specification does not define the unit of length. We
chose to implement the length facet as being in units of XML characters
in the value space ( # of chars in namespace URI + ":" +
local part );
We have interpreted the specs as requiring
<keyref> Identity Constraints to refer to
<key> or <unique> identity constraints within
the scope of the elements to which the <keyref> is
attached. This interpretation is at variance with the
Schema Primer, which contains an example with a
<keyref> declared on an element used inside the
element of its corresponding <key>;
Other Notes
The parsers contained in this package are able to read and
validate XML documents with the grammar specified in either
DTD or XML Schema format.
The schema is specified by the xsi:schemaLocation or
xsi:noNamespaceSchemaLocation attribute on the root
element of the document. The xsi prefix must be bound to the
Schema document instance namespace, as specified by the
Recommendation. See the sample provided in the
Usage section.
Usage
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:
Review the sample file, 'data/personal.xsd' for an example of an XML
Schema grammar.
PSVI and Schema Component API
Xerces provides experimental PSVI support. The PSVI augmentations can
be accessed via interfaces in the org.apache.xerces.xni.psvi
package.
From within an XMLDocumentHandler, one can retrieve PSVI
information when certain methods are called. For example,
import org.apache.xerces.xni.psvi.*;
...
public void startElement(QName element, XMLAttributes attributes,
Augmentations augs) {
ElementPSVI elemPSVI = (ElementPSVI)augs.getItem("ELEMENT_PSVI");
// get PSVI items of this element out of elemPSVI
short attemp = elemPSVI.getValidationAttempted();
short validity = elemPSVI.getValidity();
...
}
Certain PSVI item is only available on certain XMLDocumentHandler
methods. For more information, please refer to the API documentation
of the PSVI interfaces.
The above code shows how to retrieve PSVI information after
elements/attributes are assessed. The other kind of information PSVI
offers is the property
[schema information].
This property exposes all schema components in the schema that's used for
assessment. These components and the schema itself are represented by
interfaces in the org.apache.xerces.impl.xs.psvi 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
import org.apache.xerces.xni.psvi.*;
import org.apache.xerces.impl.xs.psvi.*;
...
public void endElement(QName element, Augmentations augs) {
ElementPSVI elemPSVI = (ElementPSVI)augs.getItem("ELEMENT_PSVI");
XSModel xsModel = elemPSVI.getSchemaInformation();
// get a list of [namespace schema information information item]s,
// one for each namespace.
ObjectList nsItems = xsModel.getNamespaceItems();
// get an element declaration of the specified name and namespace
XSElementDeclaration elemDecl = xsModel.getElementDeclaration
(name, namespace);
...
}