This page documents the various Java API for XML Processing (JAXP) samples included with Xerces. Besides being useful programs, they can be used as JAXP programming examples to learn how to program using the JAXP API.

JAXP samples:

A sample which demonstrates usage of classes in the javax.xml.parsers package, particularly new features introduced in JAXP 1.3 and 1.4, including XInclude processing, integration with the JAXP 1.4 Validation API and parser reset.

java jaxp.ParserAPIUsage (options) uri
OptionDescription
-a uri ...Provide a list of schema documents.
-api (sax|dom)Select API to use (sax|dom).
-xi | -XITurn on/off XInclude processing.
-sp | -SPTurn on/off secure processing.
-hDisplay help screen.

A sample demonstrating how to use the JAXP 1.4 Validation API to create a validator and use the validator to validate input from SAX, DOM or a stream. The output of this program shows the time spent executing the Validator.validate(Source) method.

This class is useful as a "poor-man's" performance tester to compare the speed of various JAXP 1.4 validators with different input sources. However, it is important to note that the first validation time of a validator will include both VM class load time and validator initialization that would not be present in subsequent validations with the same document. Also note that when the source for validation is SAX or a stream, the validation time will also include the time to parse the document, whereas the DOM validation is completely in memory.

The results produced by this program should never be accepted as true performance measurements. java jaxp.SourceValidator (options) ...
OptionDescription
-l nameSelect schema language by name.
-x numberSelect number of repetitions.
-a uri ...Provide a list of schema documents.
-i uri ...Provide a list of instance documents to validate.
-vs sourceSelect validation source (sax|dom|stax|stream).
-f | -F Turn on/off Schema full checking.
NOTE: Not supported by all schema factories and validators.
-hs | -HS Turn on/off honouring of all schema locations.
NOTE: Not supported by all schema factories and validators.
-va | -VA Turn on/off validation of schema annotations.
NOTE: Not supported by all schema factories and validators.
-ga | -GA Turn on/off generation of synthetic schema annotations.
NOTE: Not supported by all schema factories and validators.
-m | -MTurn on/off memory usage report.
-hDisplay help screen.

The speed and memory results from this program should NOT be used as the basis of parser performance comparison! Real analytical methods should be used. For better results, perform multiple validations within the same virtual machine to remove class loading from parse time and memory usage.

Not all features are supported by different parsers.

A sample demonstrating how to use the JAXP 1.4 Validation API to create a validator and use the validator to validate input from a DOM which contains inline schemas and multiple validation roots. The output of this program shows the time spent executing the Validator.validate(Source) method.

This class is useful as a "poor-man's" performance tester to compare the speed of various JAXP 1.4 validators with different input sources. However, it is important to note that the first validation time of a validator will include both VM class load time and validator initialization that would not be present in subsequent validations with the same document.

This sample makes use of the JAXP 1.3 XPath API and requires either a JAXP 1.3 compliant XSLT processor (or JDK 5.0) to run. The results produced by this program should never be accepted as true performance measurements. java jaxp.InlineSchemaValidator (options) uri ...
OptionDescription
-l nameSelect schema language by name.
-x numberSelect number of repetitions.
-a xpath ...Provide a list of XPath expressions for schema roots.
-i xpath ...Provide a list of XPath expressions for validation roots.
-nm pre uri ...Provide a list of prefix to namespace URI mappings for the XPath expressions.
-f | -F Turn on/off Schema full checking.
NOTE: Not supported by all schema factories and validators.
-hs | -HS Turn on/off honouring of all schema locations.
NOTE: Not supported by all schema factories and validators.
-va | -VA Turn on/off validation of schema annotations.
NOTE: Not supported by all schema factories and validators.
-ga | -GA Turn on/off generation of synthetic schema annotations.
NOTE: Not supported by all schema factories and validators.
-m | -MTurn on/off memory usage report.
-hDisplay help screen.

The speed and memory results from this program should NOT be used as the basis of parser performance comparison! Real analytical methods should be used. For better results, perform multiple validations within the same virtual machine to remove class loading from parse time and memory usage.

Not all features are supported by different parsers.

Provides a trace of the schema type information for elements and attributes in an XML document. This demonstrates usage of the JAXP 1.4 Validation API, particuarly how to read type information from a TypeInfoProvider.

java jaxp.TypeInfoWriter (options) ...
OptionDescription
-l nameSelect schema language by name.
-p nameSelect parser by name.
-a uri ...Provide a list of schema documents.
-i uri ...Provide a list of instance documents to validate.
-f | -F Turn on/off Schema full checking.
NOTE: Not supported by all schema factories and validators.
-hs | -HS Turn on/off honouring of all schema locations.
NOTE: Not supported by all schema factories and validators.
-va | -VA Turn on/off validation of schema annotations.
NOTE: Not supported by all schema factories and validators.
-ga | -GA Turn on/off generation of synthetic schema annotations.
NOTE: Not supported by all schema factories and validators.
-hDisplay help screen.

A sample which demonstrates usage of the JAXP 1.3 Datatype API.

java jaxp.DatatypeAPIUsage