| com.sun.xml.txw2.output.XMLWriter com.sun.xml.txw2.output.DataWriter
DataWriter | public class DataWriter extends XMLWriter (Code) | | Write data- or field-oriented XML.
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.
since: 1.0 author: David Megginson, david@megginson.com version: 0.2 See Also: XMLWriter |
DataWriter | public DataWriter(Writer writer, String encoding, CharacterEscapeHandler _escapeHandler)(Code) | | Create a new data writer for the specified output.
Parameters: writer - The character stream where the XML documentwill be written. Parameters: encoding - If non-null string is specified, it is written as a partof the XML declaration. |
characters | public void characters(char ch, int start, int length) throws SAXException(Code) | | Write a sequence of characters.
Parameters: ch - The characters to write. Parameters: start - The starting position in the array. Parameters: length - The number of characters to use. exception: org.xml.sax.SAXException - If there is an errorwriting the characters, or if a filter furtherdown the chain raises an exception. See Also: XMLWriter.characters(char[]intint) |
endElement | public void endElement(String uri, String localName, String qName) throws SAXException(Code) | | Write an end tag.
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.
Parameters: uri - The element's Namespace URI. Parameters: localName - The element's local name. Parameters: qName - The element's qualified (prefixed) name. exception: org.xml.sax.SAXException - If there is an errorwriting the end tag, or if a filter furtherdown the chain raises an exception. See Also: XMLWriter.endElement(StringStringString) |
getIndentStep | public int getIndentStep()(Code) | | Return the current indent step.
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.
The number of spaces in each indentation step,or 0 or less for no indentation. See Also: DataWriter.setIndentStep(int) |
reset | public void reset()(Code) | | Reset the writer so that it can be reused.
This method is especially useful if the writer failed
with an exception the last time through.
See Also: XMLWriter.reset |
setIndentStep | public void setIndentStep(int indentStep)(Code) | | Set the current indent step.
Parameters: indentStep - The new indent step (0 or less for noindentation). See Also: DataWriter.getIndentStep() |
startElement | public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException(Code) | | Write a start tag.
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.
Parameters: uri - The element's Namespace URI. Parameters: localName - The element's local name. Parameters: qName - The element's qualified (prefixed) name. Parameters: atts - The element's attribute list. exception: org.xml.sax.SAXException - If there is an errorwriting the start tag, or if a filter furtherdown the chain raises an exception. See Also: XMLWriter.startElement(StringStringStringAttributes) |
Methods inherited from com.sun.xml.txw2.output.XMLWriter | public void characters(char ch, int start, int len) throws SAXException(Code)(Java Doc) public void characters(String data) throws SAXException(Code)(Java Doc) public void comment(char ch, int start, int length) throws SAXException(Code)(Java Doc) public void dataElement(String uri, String localName, String qName, Attributes atts, String content) throws SAXException(Code)(Java Doc) public void dataElement(String uri, String localName, String content) throws SAXException(Code)(Java Doc) public void dataElement(String localName, String content) throws SAXException(Code)(Java Doc) public void endCDATA() throws SAXException(Code)(Java Doc) public void endDTD() throws SAXException(Code)(Java Doc) public void endDocument() throws SAXException(Code)(Java Doc) public void endElement(String uri, String localName, String qName) throws SAXException(Code)(Java Doc) public void endElement(String uri, String localName) throws SAXException(Code)(Java Doc) public void endElement(String localName) throws SAXException(Code)(Java Doc) public void endEntity(String name) throws SAXException(Code)(Java Doc) public void flush() throws IOException(Code)(Java Doc) public void ignorableWhitespace(char ch, int start, int length) throws SAXException(Code)(Java Doc) public void processingInstruction(String target, String data) throws SAXException(Code)(Java Doc) public void reset()(Code)(Java Doc) public void setEncoding(String encoding)(Code)(Java Doc) public void setHeader(String _header)(Code)(Java Doc) public void setOutput(Writer writer, String _encoding)(Code)(Java Doc) public void setXmlDecl(boolean _writeXmlDecl)(Code)(Java Doc) public void startCDATA() throws SAXException(Code)(Java Doc) public void startDTD(String name, String publicId, String systemId) throws SAXException(Code)(Java Doc) public void startDocument() throws SAXException(Code)(Java Doc) public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException(Code)(Java Doc) public void startElement(String uri, String localName) throws SAXException(Code)(Java Doc) public void startElement(String localName) throws SAXException(Code)(Java Doc) public void startEntity(String name) throws SAXException(Code)(Java Doc) public void startPrefixMapping(String prefix, String uri) throws SAXException(Code)(Java Doc)
|
|
|