## javanet.staxutils
Class IndentingXMLStreamWriter

    java.lang.Object
      javanet.staxutils.helpers.StreamWriterDelegate
          javanet.staxutils.IndentingXMLStreamWriter

All Implemented Interfaces:
  Indentation, XMLStreamWriter

    public class IndentingXMLStreamWriter

extends StreamWriterDelegate
implements Indentation

A filter that indents an XML stream. To apply it, construct a filter that contains another `XMLStreamWriter`, which you pass to the constructor. Then call methods of the filter instead of the contained stream. For example:

     XMLStreamWriter stream = ...
     stream = new IndentingXMLStreamWriter(stream);
     stream.writeStartDocument();
     ...

The filter inserts characters to format the document as an outline, with nested elements indented. Basically, it inserts a line break and whitespace before:

- each DTD, processing instruction or comment that's not preceded by data
- each starting tag that's not preceded by data
- each ending tag that's preceded by nested elements but not data

This works well with 'data-oriented' XML, wherein each element contains either data or nested elements but not both. It can work badly with other styles of XML. For example, the data in a 'mixed content' document are apt to be polluted with indentation characters.

Indentation can be adjusted by setting the newLine and indent properties. But set them to whitespace only, for best results. Non-whitespace is apt to cause problems, for example when this class attempts to insert newLine before the root element.

Author:
  John Kristian

Field Summary

Fields inherited from class javanet.staxutils.helpers.StreamWriterDelegate
`out`

Fields inherited from interface javanet.staxutils.Indentation
`DEFAULT_INDENT, NORMAL_END_OF_LINE`

Constructor Summary
`IndentingXMLStreamWriter(XMLStreamWriter out)`

Method Summary
`protected void` `afterData()` Note that data were written.
`protected void` `afterEndDocument()` Note that a document was ended.
`protected void` `afterEndElement()` Note that an element was ended.
`protected void` `afterMarkup()` Note that markup or indentation was written.
`protected void` `afterStartElement()` Note that an element was started.
`protected void` `beforeEndElement()` Prepare to end an element, by writing a new line and indentation.
`protected void` `beforeMarkup()` Prepare to write markup, by writing a new line and indentation.
`protected void` `beforeStartElement()` Prepare to start an element, by allocating stack space.
`String` `getIndent()` The characters used for one level of indentation.
`static String` `getLineSeparator()`
`String` `getNewLine()` The characters that introduce a new line.
`void` `setIndent(String indent)` Set the characters used for one level of indentation.
`void` `setNewLine(String newLine)` Set the characters that introduce a new line.
`void` `writeCData(String data)`
`void` `writeCharacters(char[] text, int start, int len)`
`void` `writeCharacters(String text)`
`void` `writeComment(String data)`
`void` `writeDTD(String dtd)`
`void` `writeEmptyElement(String localName)`
`void` `writeEmptyElement(String namespaceURI, String localName)`
`void` `writeEmptyElement(String prefix, String localName, String namespaceURI)`
`void` `writeEndDocument()`
`void` `writeEndElement()`
`void` `writeEntityRef(String name)`
`protected void` `writeNewLine(int indentation)` Write a line separator followed by indentation.
`void` `writeProcessingInstruction(String target)`
`void` `writeProcessingInstruction(String target, String data)`
`void` `writeStartDocument()`
`void` `writeStartDocument(String version)`
`void` `writeStartDocument(String encoding, String version)`
`void` `writeStartElement(String localName)`
`void` `writeStartElement(String namespaceURI, String localName)`
`void` `writeStartElement(String prefix, String localName, String namespaceURI)`

Methods inherited from class javanet.staxutils.helpers.StreamWriterDelegate
`close, flush, getNamespaceContext, getPrefix, getProperty, setDefaultNamespace, setNamespaceContext, setPrefix, writeAttribute, writeAttribute, writeAttribute, writeDefaultNamespace, writeNamespace`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### IndentingXMLStreamWriter

    public IndentingXMLStreamWriter(XMLStreamWriter out)

Method Detail

### setIndent

    public void setIndent(String indent)

  Description copied from interface: `Indentation`
  Set the characters used for one level of indentation. The default is `Indentation.DEFAULT_INDENT`. "\t" is a popular alternative.

  Specified by:
    `setIndent` in interface `Indentation`

### getIndent

    public String getIndent()

  Description copied from interface: `Indentation`
  The characters used for one level of indentation.

  Specified by:
    `getIndent` in interface `Indentation`

### setNewLine

    public void setNewLine(String newLine)

  Description copied from interface: `Indentation`
  Set the characters that introduce a new line. The default is `Indentation.NORMAL_END_OF_LINE`. `getLineSeparator()`() is a popular alternative.

  Specified by:
    `setNewLine` in interface `Indentation`

### getLineSeparator

    public static String getLineSeparator()

  Returns:
    System.getProperty("line.separator"); or `Indentation.NORMAL_END_OF_LINE` if that fails.

### getNewLine

    public String getNewLine()

  Description copied from interface: `Indentation`
  The characters that introduce a new line.

  Specified by:
    `getNewLine` in interface `Indentation`

### writeStartDocument

    public void writeStartDocument()
                            throws XMLStreamException

  Specified by:
    `writeStartDocument` in interface `XMLStreamWriter`
  Overrides:
    `writeStartDocument` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeStartDocument

    public void writeStartDocument(String version)
                            throws XMLStreamException

  Specified by:
    `writeStartDocument` in interface `XMLStreamWriter`
  Overrides:
    `writeStartDocument` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeStartDocument

    public void writeStartDocument(String encoding,
                                   String version)
                            throws XMLStreamException

  Specified by:
    `writeStartDocument` in interface `XMLStreamWriter`
  Overrides:
    `writeStartDocument` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeDTD

    public void writeDTD(String dtd)
                  throws XMLStreamException

  Specified by:
    `writeDTD` in interface `XMLStreamWriter`
  Overrides:
    `writeDTD` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeProcessingInstruction

    public void writeProcessingInstruction(String target)
                                    throws XMLStreamException

  Specified by:
    `writeProcessingInstruction` in interface `XMLStreamWriter`
  Overrides:
    `writeProcessingInstruction` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeProcessingInstruction

    public void writeProcessingInstruction(String target,
                                           String data)
                                    throws XMLStreamException

  Specified by:
    `writeProcessingInstruction` in interface `XMLStreamWriter`
  Overrides:
    `writeProcessingInstruction` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeComment

    public void writeComment(String data)
                      throws XMLStreamException

  Specified by:
    `writeComment` in interface `XMLStreamWriter`
  Overrides:
    `writeComment` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeEmptyElement

    public void writeEmptyElement(String localName)
                           throws XMLStreamException

  Specified by:
    `writeEmptyElement` in interface `XMLStreamWriter`
  Overrides:
    `writeEmptyElement` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeEmptyElement

    public void writeEmptyElement(String namespaceURI,
                                  String localName)
                           throws XMLStreamException

  Specified by:
    `writeEmptyElement` in interface `XMLStreamWriter`
  Overrides:
    `writeEmptyElement` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeEmptyElement

    public void writeEmptyElement(String prefix,
                                  String localName,
                                  String namespaceURI)
                           throws XMLStreamException

  Specified by:
    `writeEmptyElement` in interface `XMLStreamWriter`
  Overrides:
    `writeEmptyElement` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeStartElement

    public void writeStartElement(String localName)
                           throws XMLStreamException

  Specified by:
    `writeStartElement` in interface `XMLStreamWriter`
  Overrides:
    `writeStartElement` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeStartElement

    public void writeStartElement(String namespaceURI,
                                  String localName)
                           throws XMLStreamException

  Specified by:
    `writeStartElement` in interface `XMLStreamWriter`
  Overrides:
    `writeStartElement` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeStartElement

    public void writeStartElement(String prefix,
                                  String localName,
                                  String namespaceURI)
                           throws XMLStreamException

  Specified by:
    `writeStartElement` in interface `XMLStreamWriter`
  Overrides:
    `writeStartElement` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeCharacters

    public void writeCharacters(String text)
                         throws XMLStreamException

  Specified by:
    `writeCharacters` in interface `XMLStreamWriter`
  Overrides:
    `writeCharacters` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeCharacters

    public void writeCharacters(char[] text,
                                int start,
                                int len)
                         throws XMLStreamException

  Specified by:
    `writeCharacters` in interface `XMLStreamWriter`
  Overrides:
    `writeCharacters` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeCData

    public void writeCData(String data)
                    throws XMLStreamException

  Specified by:
    `writeCData` in interface `XMLStreamWriter`
  Overrides:
    `writeCData` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeEntityRef

    public void writeEntityRef(String name)
                        throws XMLStreamException

  Specified by:
    `writeEntityRef` in interface `XMLStreamWriter`
  Overrides:
    `writeEntityRef` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeEndElement

    public void writeEndElement()
                         throws XMLStreamException

  Specified by:
    `writeEndElement` in interface `XMLStreamWriter`
  Overrides:
    `writeEndElement` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### writeEndDocument

    public void writeEndDocument()
                          throws XMLStreamException

  Specified by:
    `writeEndDocument` in interface `XMLStreamWriter`
  Overrides:
    `writeEndDocument` in class `StreamWriterDelegate`
  Throws:
    `XMLStreamException`

### beforeMarkup

    protected void beforeMarkup()

  Prepare to write markup, by writing a new line and indentation.

### afterMarkup

    protected void afterMarkup()

  Note that markup or indentation was written.

### afterData

    protected void afterData()

  Note that data were written.

### beforeStartElement

    protected void beforeStartElement()

  Prepare to start an element, by allocating stack space.

### afterStartElement

    protected void afterStartElement()

  Note that an element was started.

### beforeEndElement

    protected void beforeEndElement()

  Prepare to end an element, by writing a new line and indentation.

### afterEndElement

    protected void afterEndElement()

  Note that an element was ended.

### afterEndDocument

    protected void afterEndDocument()

  Note that a document was ended.

### writeNewLine

    protected void writeNewLine(int indentation)
                         throws XMLStreamException

  Write a line separator followed by indentation.

  Throws:
    `XMLStreamException`