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

P2P Networks Introduction




















Advertisements

High-Performance
Java Persistence
Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next