java.lang.Objectorg.xml.sax.helpers.XMLFilterImpl
com.sun.xml.internal.txw2.output.XMLWriter
com.sun.xml.internal.txw2.output.DataWriter
All Implemented Interfaces:
LexicalHandler, ContentHandler, DTDHandler, ErrorHandler, XMLFilter, EntityResolver
This filter pretty-prints field-oriented XML without mixed content. all added indentation and newlines will be passed on down the filter chain (if any).
In general, all whitespace in an XML document is potentially significant, so a general-purpose XML writing tool like the XMLWriter class cannot add newlines or indentation.
There is, however, a large class of XML documents where information is strictly fielded: each element contains either character data or other elements, but not both. For this special case, it is possible for a writing tool to provide automatic indentation and newlines without requiring extra work from the user. Note that this class will likely not yield appropriate results for document-oriented XML like XHTML pages, which mix character data and elements together.
This writer will automatically place each start tag on a new line, optionally indented if an indent step is provided (by default, there is no indentation). If an element contains other elements, the end tag will also appear on a new line with leading indentation. Consider, for example, the following code:
DataWriter w = new DataWriter();
w.setIndentStep(2);
w.startDocument();
w.startElement("Person");
w.dataElement("name", "Jane Smith");
w.dataElement("date-of-birth", "1965-05-23");
w.dataElement("citizenship", "US");
w.endElement("Person");
w.endDocument();
This code will produce the following document:
<?xml version="1.0" standalone="yes"?> <Person> <name>Jane Smith</name> <date-of-birth>1965-05-23</date-of-birth> <citizenship>US</citizenship> </Person>
This class inherits from XMLWriter , and provides all of the same support for Namespaces.
1.0 - David - Megginson, david@megginson.com| Constructor: |
|---|
|
|
|
| Method from com.sun.xml.internal.txw2.output.DataWriter Summary: |
|---|
| characters, comment, endElement, getIndentStep, reset, setIndentStep, setIndentStep, startElement |
| Methods from com.sun.xml.internal.txw2.output.XMLWriter: |
|---|
| characters, characters, comment, dataElement, dataElement, dataElement, endCDATA, endDTD, endDocument, endElement, endElement, endElement, endEntity, flush, ignorableWhitespace, processingInstruction, reset, setEncoding, setHeader, setOutput, setXmlDecl, startCDATA, startDTD, startDocument, startElement, startElement, startElement, startEntity, startPrefixMapping |
| Methods from org.xml.sax.helpers.XMLFilterImpl: |
|---|
| characters, endDocument, endElement, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, ignorableWhitespace, notationDecl, parse, parse, processingInstruction, resolveEntity, setContentHandler, setDTDHandler, setDocumentLocator, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl, warning |
| Methods from java.lang.Object: |
|---|
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from com.sun.xml.internal.txw2.output.DataWriter Detail: |
|---|
|
|
If the element has contained other elements, the tag will appear indented on a new line; otherwise, it will appear immediately following whatever came before. The newline and indentation will be passed on down the filter chain through regular characters events. |
Deprecated! Only - return the length of the indent string.
Return the current indent step: each start tag will be indented by this number of spaces times the number of ancestors that the element has. |
This method is especially useful if the writer failed with an exception the last time through. |
Deprecated! Should - use the version that takes string.
|
|
Each tag will begin on a new line, and will be indented by the current indent step times the number of ancestors that the element has. The newline and indentation will be passed on down the filter chain through regular characters events. |