background image

StAX Factory Classes

<< Comparing Cursor and Iterator APIs | XMLOutputFactory >>
<< Comparing Cursor and Iterator APIs | XMLOutputFactory >>
U
SING
S
T
AX
89
Using StAX
In general, StAX programmers create XML stream readers, writers, and events
by using the
XMLInputFactory
,
XMLOutputFactory
and
XMLEventFactory
classes. Configuration is done by setting properties on the factories, whereby
implementation-specific settings can be passed to the underlying implementation
using the
setProperty()
method on the factories. Similarly, implementation-
specific settings can be queried using the
getProperty()
factory method.
The
XMLInputFactory
,
XMLOutputFactory
and
XMLEventFactory
classes are
described below, followed by discussions of resource allocation, namespace and
attribute management, error handling, and then finally reading and writing
streams using the cursor and iterator APIs.
StAX Factory Classes
XMLInputFactory
The
XMLInputFactory
class lets you configure implementation instances of
XML stream reader processors created by the factory. New instances of the
abstract class
XMLInputFactory
are created by calling the
newInstance()
method on the class. The static method
XMLInputFactory.newInstance()
is
then used to create a new factory instance.
Deriving from JAXP, the
XMLInputFactory.newInstance()
method deter-
mines the specific
XMLInputFactory
implementation class to load by using the
following lookup procedure:
1. Use the
javax.xml.stream.XMLInputFactory
system property.
2. Use the
lib/xml.stream.properties
file in the JRE directory.
3. Use the Services API, if available, to determine the classname by looking
in the
META-INF/services/javax.xml.stream.XMLInputFactory
files
in jars available to the JRE.
4. Use the platform default
XMLInputFactory
instance.
After getting a reference to an appropriate XMLInputFactory, an application can
use the factory to configure and create stream instances. Table 4­4 lists the prop-