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 {@link XMLWriter} class cannotadd 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 {@link XMLWriter}, and provides all of the same support for Namespaces.
@since 1.0 @author David Megginson, david@megginson.com @version 0.2 @see XMLWriter
|
|
|
|
|
|
|
|
|
|
|
|