The Xerces Native Interface (XNI) is an internal API that is independent of other XML APIs and is used to implement the Xerces family of parsers. XNI allows a wide variety of parsers to be written in an easy and modular fashion. The XNI samples included with Xerces are simple examples of how to program using the XNI API. However, for information on how to take full advantage of this powerful framework, refer to the XNI Manual.
Basic XNI samples:
Parser configuration samples:
Most of the XNI samples have a command line option that allows the
user to specify a different XNI parser configuration to use. In
order to supply another parser configuration besides the default
Xerces StandardParserConfiguration
, the configuration
must implement the
org.apache.xerces.xni.parser.XMLParserConfiguration
interface.
A sample XNI counter. 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 parser configurations. 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.
Option | Description |
---|---|
-p name | Select parser configuration 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 parser configurations. |
-f | -F |
Turn on/off Schema full checking. NOTE: Requires use of -s 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. |
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 parser configurations.
Provides a complete trace of XNI document and DTD events for files parsed.
Option | Description |
---|---|
-p name | Specify parser configuration by name. |
-n | -N | Turn on/off namespace processing. |
-v | -V | Turn on/off validation. |
-s | -S |
Turn on/off Schema validation support. NOTE: Not supported by all parser configurations. |
-c | -C | Turn on/off character notifications"); |
-h | Display help screen. |
A sample XNI writer. This sample program illustrates how to take receive XMLDocumentHandler callbacks in order to print a document that is parsed.
Option | Description |
---|---|
-p name | Select parser configuration by name. |
-n | -N | Turn on/off namespace processing. |
-v | -V | Turn on/off validation. |
-s | -S |
Turn on/off Schema validation support. NOTE: Not supported by all parser configurations. |
-h | Display help screen. |
This sample demonstrates how to implement a simple pass-through filter for the document "streaming" information set using XNI. This filter could be used in a pipeline of XNI parser components that communicate document events.
This class can NOT be run as a standalone program. It is only an example of how to write a document handler.
This sample demonstrates how to create a filter for the document "streaming" information set that turns element names into upper case.
This class can NOT be run as a standalone program. It is only an example of how to write a document handler.
Non-validating parser configuration.
This class can NOT be run as a standalone
program. It is only an example of how to write a parser
configuration using XNI. You can use this parser configuration
by specifying the fully qualified class name to all of the XNI
samples that accept a parser configuration using the
-p
option. For example:
This abstract parser configuration simply helps manage components, features and properties, and other tasks common to all parser configurations. In order to subclass this configuration and use it effectively, the subclass is required to do the following:
addComponent
method,parse
method, andresetComponents
before parsing.This class can NOT be run as a standalone program. It is only an example of how to write a parser configuration using XNI.
This example is a very simple parser configuration that can parse files with comma-separated values (CSV) to generate XML events. For example, the following CSV document:
produces the following XML "document" as represented by the XNI streaming document information:
This class can NOT be run as a standalone
program. It is only an example of how to write a parser
configuration using XNI. You can use this parser configuration
by specifying the fully qualified class name to all of the XNI
samples that accept a parser configuration using the
-p
option. For example:
This parser class implements a SAX parser that can parse simple comma-separated value (CSV) files.
This class can NOT be run as a standalone
program. It is only an example of how to write a parser
using XNI. You can use this parser
by specifying the fully qualified class name to all of the SAX
samples that accept a parser using the
-p
option. For example: