| Overview |
| This page documents the various Simple API for XML (SAX) samples included with Xerces. Besides being useful programs, they can be used as SAX programming examples to learn how to program using the SAX API. SAX samples: sax.Counter sax.DocumentTracer sax.Writer Most of the SAX parser samples have a command line option that allows the user to specify a different parser to use. In order to supply another SAX parser besides the default Xerces `SAXParser`, the parser must implement either the `org.xml.sax.Parser` or `org.xml.sax.XMLReader` interfaces. You may specify xni.parser.PSVIParser if you want Xerces to output PSVI.
| JAXP could be used instead but this feature is not implemented at this time. Using JAXP would require the user to specify the `-Djavax.xml.parsers.SAXParserFactory=...` option to the virtual machine in order to use a different SAX parser factory.
| Sample sax.Counter |
| A sample SAX2 counter. This sample program illustrates how to register a SAX2 ContentHandler and receive the callbacks in order to print information about the document. The output of this program shows the time and count of elements, attributes, ignorable whitespaces, and characters appearing in the document. This class is useful as a "poor-man's" performance tester to compare the speed and accuracy of various SAX parsers. However, it is important to note that the first parse time of a parser will include both VM class load time and parser initialization that would not be present in subsequent parses with the same file.
| The results produced by this program should never be accepted as true performance measurements.
| usage |
    java sax.Counter (options) uri ...
| options |
Option | Description
-p name | Select parser by name.
-x number | Select number of repetitions.
-n | -N | Turn on/off namespace processing.
-np | -NP | Turn on/off namespace prefixes. NOTE: Requires use of -n.
-v | -V | Turn on/off validation.
-s | -S | Turn on/off Schema validation support. NOTE: Not supported by all parsers.
-f | -F | Turn on/off Schema full checking. NOTE: Requires use of -s and not supported by all parsers.
-hs | -HS | Turn on/off honouring of all schema locations. NOTE: Requires use of -s and not supported by all parsers.
-va | -VA | Turn on/off validation of schema annotations. NOTE: Requires use of -s and not supported by all parsers.
-dv | -DV | Turn on/off dynamic validation. NOTE: Not supported by all parsers.
-xi | -XI | Turn on/off XInclude processing. NOTE: Not supported by all parsers.
-xb | -XB | Turn on/off base URI fixup during XInclude processing. NOTE: Requires use of -xi and not supported by all parsers.
-xl | -XL | Turn on/off language fixup during XInclude processing. NOTE: Requires use of -xi and not supported by all parsers.
-m | -M | Turn on/off memory usage report.
-t | -T | Turn on/off \"tagginess\" report.
--rem text | Output user defined comment before next parse.
-h | Display help screen.
| notes |
| 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 document parses within the same virtual machine to remove class loading from parse time and memory usage. The "tagginess" measurement gives a rough estimate of the percentage of markup versus content in the XML document. The percent tagginess of a document is equal to the minimum amount of tag characters required for elements, attributes, and processing instructions divided by the total amount of characters (characters, ignorable whitespace, and tag characters) in the document. Not all features are supported by different parsers.
| Sample sax.DocumentTracer |
| Provides a complete trace of SAX2 events for files parsed. This is useful for making sure that a SAX parser implementation faithfully communicates all information in the document to the SAX handlers.
| usage |
    java sax.DocumentTracer (options) uri ...
| options |
Option | Description
-p name | Select parser by name.
-n | -N | Turn on/off namespace processing.
-np | -NP | Turn on/off namespace prefixes. NOTE: Requires use of -n.
-v | -V | Turn on/off validation.
-xd | -XD | Turn on/off loading of external DTDs. NOTE: Always on when -v in use and not supported by all parsers.
-s | -S | Turn on/off Schema validation support. NOTE: Not supported by all parsers.
-f | -F | Turn on/off Schema full checking. NOTE: Requires use of -s and not supported by all parsers.
-hs | -HS | Turn on/off honouring of all schema locations. NOTE: Requires use of -s and not supported by all parsers.
-va | -VA | Turn on/off validation of schema annotations. NOTE: Requires use of -s and not supported by all parsers.
-dv | -DV | Turn on/off dynamic validation. NOTE: Not supported by all parsers.
-xi | -XI | Turn on/off XInclude processing. NOTE: Not supported by all parsers.
-xb | -XB | Turn on/off base URI fixup during XInclude processing. NOTE: Requires use of -xi and not supported by all parsers.
-xl | -XL | Turn on/off language fixup during XInclude processing. NOTE: Requires use of -xi and not supported by all parsers.
-h | Display help screen.
| Sample sax.Writer |
| A sample SAX2 writer. This sample program illustrates how to register a SAX2 ContentHandler and receive the callbacks in order to print a document that is parsed.
| usage |
    java sax.Writer (options) uri ...
| options |
Option | Description
-p name | Select parser by name.
-n | -N | Turn on/off namespace processing.
-np | -NP | Turn on/off namespace prefixes. NOTE: Requires use of -n.
-v | -V | Turn on/off validation.
-xd | -XD | Turn on/off loading of external DTDs. NOTE: Always on when -v in use and not supported by all parsers.
-s | -S | Turn on/off Schema validation support. NOTE: Not supported by all parsers.
-f | -F | Turn on/off Schema full checking. NOTE: Requires use of -s and not supported by all parsers.
-hs | -HS | Turn on/off honouring of all schema locations. NOTE: Requires use of -s and not supported by all parsers.
-va | -VA | Turn on/off validation of schema annotations. NOTE: Requires use of -s and not supported by all parsers.
-ga | -GA | Turn on/off generation of synthetic schema annotations. NOTE: Requires use of -s and not supported by all parsers.
-dv | -DV | Turn on/off dynamic validation. NOTE: Not supported by all parsers.
-xi | -XI | Turn on/off XInclude processing. NOTE: Not supported by all parsers.
-xb | -XB | Turn on/off base URI fixup during XInclude processing. NOTE: Requires use of -xi and not supported by all parsers.
-xl | -XL | Turn on/off language fixup during XInclude processing. NOTE: Requires use of -xi and not supported by all parsers.
-c | -C | Turn on/off Canonical XML output. NOTE: This is not W3C canonical output.
-h | Display help screen.

Copyright © 1999-2007 The Apache Software Foundation. All Rights Reserved.