Class XMLOutputter

java.lang.Object
org.znerd.xmlenc.XMLOutputter
All Implemented Interfaces:
StatefulXMLEventListener, XMLEventListener, XMLEventListenerStates

public class XMLOutputter extends Object implements StatefulXMLEventListener
Stream-based XML outputter. Instances of this class are able to write XML output to Writers.

Standards compliance

This class is intended to produce output that conforms to the XML 1.0 Specification. However, not all applicable restrictions are validated. For example, it is currently not checked if names contain characters that are invalid within a Name production.

Furthermore, not all possible XML documents can be produced. The following limitations apply:

  • The name of the applicable encoding is always printed in the XML declaration, even though it may not be necessary.
  • The standalone attribute is not supported in the XML declaration.
  • Internal DTD subsets are not supported.
  • Spacing is fixed, whitespace is always kept to the minimum.

Supported encodings

The following encodings are supported:
  • UTF-8
  • UTF-16
  • ISO-10646-UCS-2
  • ISO-10646-UCS-4
  • ISO-10646-UTF-1
  • US-ASCII (also known as ASCII)
  • ISO-8859-n, where n is the part number

Multi-threading

This class is not thread-safe.

Exceptions

Note that all methods check the state first and then check the arguments. This means that if the state is incorrect and the arguments are incorrect, then an IllegalStateException will be thrown.

If any of the writing methods generates an IOException, then the state will be set to XMLEventListenerStates.ERROR_STATE and no more output can be performed.

Performance hints

It is usually a good idea to let XMLOutputter instances write to buffered Writers. This typically improves performance on large documents or relatively slow or blocking output streams.

Instances of this class can be cached in a pool to reduce object creations. Call reset() (with no arguments) when storing an instance in the pool. Use reset(Writer,String) (with 2 arguments) to re-initialize the instance after fetching it from the pool.

Since:
xmlenc 0.19
Version:
$Revision: 1.118 $ $Date: 2005/09/12 08:40:02 $
Author:
Ernst de Haan (wfe.dehaan@gmail.com), Jochen Schwoerer (j.schwoerer [at] web.de)