edu.northwestern.at.utils.xml

## Class IndentingXMLWriter

- java.lang.Object
- - org.xml.sax.helpers.XMLFilterImpl
  - - com.megginson.sax.XMLWriter
    - - edu.northwestern.at.utils.xml.IndentingXMLWriter

- All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.XMLFilter, org.xml.sax.XMLReader

      public class IndentingXMLWriter
      extends XMLWriter

  XMLWriter which indents the output before each tag.

  This code assumes the XML is not currently indented.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected QueueStack<java.lang.Boolean>` | `childStack` Stack which remembers if a tag has at least one child.
    `protected char[]` | `eol` End of line character(s).
    `protected char[]` | `indents` Blanks for indentation.
    `protected int` | `indentStep` Number of spaces to indent each level of XML.

    - ### Fields inherited from class com.megginson.sax.XMLWriter

      `LINE_SEPARATOR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `IndentingXMLWriter(org.xml.sax.XMLReader xmlReader, java.io.Writer writer)` Create indenting XML writer.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)` Handle end of an element.
    `int` | `getIndentStep()` Return the current indent step.
    `void` | `setIndentStep(int indentStep)` Set the current indent step.
    `void` | `startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)` Handle start of an XML element.

    - ### Methods inherited from class com.megginson.sax.XMLWriter

      `characters, characters, dataElement, dataElement, dataElement, emptyElement, emptyElement, emptyElement, endDocument, endElement, endElement, flush, forceNSDecl, forceNSDecl, getPrefix, ignorableWhitespace, processingInstruction, reset, setDoctype, setOutput, setOutputCharsAsIs, setPrefix, startDocument, startElement, startElement, write, write, writeEsc`

    - ### Methods inherited from class org.xml.sax.helpers.XMLFilterImpl

      `endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, notationDecl, parse, parse, resolveEntity, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### indentStep

          protected int indentStep

      Number of spaces to indent each level of XML.

    - #### indents

          protected char[] indents

      Blanks for indentation.

    - #### eol

          protected char[] eol

      End of line character(s).

    - #### childStack

          protected QueueStack<java.lang.Boolean> childStack

      Stack which remembers if a tag has at least one child.

      The start and end tags of an element with no children are kept on the same line.

  - ### Constructor Detail

    - #### IndentingXMLWriter

          public IndentingXMLWriter(org.xml.sax.XMLReader xmlReader,
                            java.io.Writer writer)

      Create indenting XML writer.
      Parameters:
        `xmlReader` - The XML Reader to which this writer is attached.
        `writer` - The output writer to which to output the indented XML.

  - ### Method Detail

    - #### getIndentStep

          public int getIndentStep()

      Return the current indent step.
      Returns:
        The number of indents in each indentation step. 0 or less for no indentation.

    - #### setIndentStep

          public void setIndentStep(int indentStep)

      Set the current indent step.
      Parameters:
        `indentStep` - The new indent step (0 or less for no indentation).

    - #### startElement

          public void startElement(java.lang.String uri,
                          java.lang.String localName,
                          java.lang.String qName,
                          org.xml.sax.Attributes atts)
                            throws org.xml.sax.SAXException

      Handle start of an XML element.
      Specified by:
        `startElement` in interface `org.xml.sax.ContentHandler`
      Overrides:
        `startElement` in class `XMLWriter`
      Parameters:
        `uri` - The XML element's URI.
        `localName` - The XML element's local name.
        `qName` - The XML element's qname.
        `atts` - The XML element's attributes.
      Throws:
        `org.xml.sax.SAXException` - If there is an error writing the start tag, or if a handler further down the filter chain raises an exception.
      See Also:
        `ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)`

    - #### endElement

          public void endElement(java.lang.String uri,
                        java.lang.String localName,
                        java.lang.String qName)
                          throws org.xml.sax.SAXException

      Handle end of an element.
      Specified by:
        `endElement` in interface `org.xml.sax.ContentHandler`
      Overrides:
        `endElement` in class `XMLWriter`
      Parameters:
        `uri` - The XML element's URI.
        `localName` - The XML element's local name.
        `qName` - The XML element's qname.
      Throws:
        `org.xml.sax.SAXException` - If there is an error writing the end tag, or if a handler further down the filter chain raises an exception.
      See Also:
        `ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)`