background image

Example Code

<< Streaming XML Parser Implementation | Example XML Document >>
<< Streaming XML Parser Implementation | Example XML Document >>

Example Code

However, there may be scenarios when an application would like to know about the factory
implementation class name and set the property explicitly. These scenarios could include cases
where there are multiple JSR 173 implementations in the classpath and the application wants to
choose one, perhaps one that has superior performance, contains a crucial bug fix, or suchlike.
If an application sets the SystemProperty, it is the first step in a lookup operation, and so
obtaining the factory instance would be fast compared to other options; for example:
javax.xml.stream.XMLInputFactory -->
com.sun.xml.stream.ZephyrParserFactory
javax.xml.stream.XMLOutputFactory -->
com.sun.xml.stream.ZephyrWriterFactor
javax.xml.stream.XMLEventFactory -->
com.sun.xml.stream.events.ZephyrEventFactory
Example Code
This section steps through the example StAX code included in the Java EE 5 Tutorial bundle. All
example directories used in this section are located in the
tut-install/javaeetutorial5/examples/stax/ directory.
The topics covered in this section are as follows:
"Example Code Organization" on page 567
"Example XML Document" on page 568
"Cursor Example" on page 568
"Cursor-to-Event Example" on page 571
"Event Example" on page 573
"Filter Example" on page 575
"Read-and-Write Example" on page 578
"Writer Example" on page 580
Example Code Organization
The tut-install/javaeetutorial5/examples/stax/ directory contains the six StAX example
directories:
Cursor example
: The cursor directory contains CursorParse.java, which illustrates how
to use the XMLStreamReader (cursor) API to read an XML file.
Cursor-to-Event example
: The cursor2event directory contains
CursorApproachEventObject.java
, which illustrates how an application can get
information as an XMLEvent object when using cursor API.
Event example
: The event directory contains EventParse.java, which illustrates how to
use the XMLEventReader (event iterator) API to read an XML file.
Example Code
Chapter 18 · Streaming API for XML
567