Package org.dom4j.io

Class XMLWriter

  • All Implemented Interfaces:
    ContentHandler, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler, XMLFilter, XMLReader
    Direct Known Subclasses:
    HTMLWriter

    public class XMLWriter
    extends XMLFilterImpl
    implements LexicalHandler

    XMLWriter takes a DOM4J tree and formats it to a stream as XML. It can also take SAX events too so can be used by SAX clients as this object implements the ContentHandlerand LexicalHandler interfaces. as well. This formatter performs typical document formatting. The XML declaration and processing instructions are always on their own lines. An OutputFormatobject can be used to define how whitespace is handled when printing and allows various configuration options, such as to allow suppression of the XML declaration, the encoding declaration or whether empty documents are collapsed.

    There are write(...) methods to print any of the standard DOM4J classes, including Document and Element, to either a Writer or an OutputStream. Warning: using your own Writer may cause the writer's preferred character encoding to be ignored. If you use encodings other than UTF8, we recommend using the method that takes an OutputStream instead.