public class IndentingXMLWriter extends XMLWriter
This code assumes the XML is not currently indented.
| 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.
|
LINE_SEPARATOR| Constructor and Description |
|---|
IndentingXMLWriter(org.xml.sax.XMLReader xmlReader,
java.io.Writer writer)
Create indenting XML writer.
|
| 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.
|
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, writeEscendPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, notationDecl, parse, parse, resolveEntity, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startPrefixMapping, unparsedEntityDecl, warningprotected int indentStep
protected char[] indents
protected char[] eol
protected QueueStack<java.lang.Boolean> childStack
The start and end tags of an element with no children are kept on the same line.
public IndentingXMLWriter(org.xml.sax.XMLReader xmlReader,
java.io.Writer writer)
xmlReader - The XML Reader to which this writer is attached.writer - The output writer to which to output the
indented XML.public int getIndentStep()
public void setIndentStep(int indentStep)
indentStep - The new indent step (0 or less for no
indentation).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
startElement in interface org.xml.sax.ContentHandlerstartElement in class XMLWriteruri - The XML element's URI.localName - The XML element's local name.qName - The XML element's qname.atts - The XML element's attributes.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.ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)public void endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
throws org.xml.sax.SAXException
endElement in interface org.xml.sax.ContentHandlerendElement in class XMLWriteruri - The XML element's URI.localName - The XML element's local name.qName - The XML element's qname.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.ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)