Java StAX: XMLOutputFactory

Jakob Jenkov
Last update: 2014-05-21

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

XMLOutputFactory factory = XMLOutputFactory.newInstance();

XMLEventWriter eventWriter =
    factory.createXMLEventWriter(
        new FileWriter("data\\test.xml"));

XMLStreamWriter streamWriter =
    factory.createXMLStreamWriter(
        new FileWriter("data\\test.xml"));

XMLOutputFactory Properties

You can set one property on the XMLOutputFactory instance using the setProperty() method. Here is an example:

factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, 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