Java StAX: XMLInputFactory
Jakob Jenkov |
The Java class javax.xml.stream.XMLInputFactory
is one of the root component of the Java StAX API.
From this class you can create both an XMLStreamReader
and an XMLEventReader
instance.
The XMLStreamReader
and XMLEventReader
instances are used to parse XML using either
a stream-of-tokens approach, or an event-based (callback based) approach. You can read more about these classes
in Java Stax XMLEventReader and Java Stax XMLStreamReader.
Here are two examples showing how to create an XMLEventReader and an XMLStreamReader :
XMLInputFactory factory = XMLInputFactory.newInstance(); XMLEventReader eventReader = factory.createXMLEventReader( new FileReader("data\\test.xml")); XMLStreamReader streamReader = factory.createXMLStreamReader( new FileReader("data\\test.xml"));
XMLInputFactory Properties
You can set various properties on the XMLInputFactory
instance using the
setProperty()
method. Here is an example:
factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
For a full list of properties and their meaning, see the official JavaDoc for the StAX API.
Tweet | |
Jakob Jenkov |