Java StAX: XMLInputFactory

Jakob Jenkov
Last update: 2014-05-21

The class javax.xml.stream.XMLInputFactory is a root component of the Java StAX API. From this class you can create both an XMLStreamReader and an XMLEventReader. Here are two examples:

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 (in Java 6) for the StAX API.

Jakob Jenkov

Featured Videos









Core Software Performance Optimization Principles

Thread Congestion in Java - Video Tutorial








Advertisements

High-Performance
Java Persistence
Close TOC

All Trails

Trail TOC

Page TOC

Previous

Next