public class IndentingXMLStreamWriter extends StreamWriterDelegate implements Indentation
XMLStreamWriter, which you pass to the constructor.
Then call methods of the filter instead of the contained stream. For example:
XMLStreamWriterstream = ... stream = newIndentingXMLStreamWriter(stream); stream.writeStartDocument(); ...
The filter inserts characters to format the document as an outline, with nested elements indented. Basically, it inserts a line break and whitespace before:
Indentation can be adjusted by setting the newLine and indent properties. But set them to whitespace only, for best results. Non-whitespace is apt to cause problems, for example when this class attempts to insert newLine before the root element.
outDEFAULT_INDENT, NORMAL_END_OF_LINE| Constructor and Description |
|---|
IndentingXMLStreamWriter(XMLStreamWriter out) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterData()
Note that data were written.
|
protected void |
afterEndDocument()
Note that a document was ended.
|
protected void |
afterEndElement()
Note that an element was ended.
|
protected void |
afterMarkup()
Note that markup or indentation was written.
|
protected void |
afterStartElement()
Note that an element was started.
|
protected void |
beforeEndElement()
Prepare to end an element, by writing a new line and indentation.
|
protected void |
beforeMarkup()
Prepare to write markup, by writing a new line and indentation.
|
protected void |
beforeStartElement()
Prepare to start an element, by allocating stack space.
|
String |
getIndent()
The characters used for one level of indentation.
|
static String |
getLineSeparator() |
String |
getNewLine()
The characters that introduce a new line.
|
void |
setIndent(String indent)
Set the characters used for one level of indentation.
|
void |
setNewLine(String newLine)
Set the characters that introduce a new line.
|
void |
writeCData(String data) |
void |
writeCharacters(char[] text,
int start,
int len) |
void |
writeCharacters(String text) |
void |
writeComment(String data) |
void |
writeDTD(String dtd) |
void |
writeEmptyElement(String localName) |
void |
writeEmptyElement(String namespaceURI,
String localName) |
void |
writeEmptyElement(String prefix,
String localName,
String namespaceURI) |
void |
writeEndDocument() |
void |
writeEndElement() |
void |
writeEntityRef(String name) |
protected void |
writeNewLine(int indentation)
Write a line separator followed by indentation.
|
void |
writeProcessingInstruction(String target) |
void |
writeProcessingInstruction(String target,
String data) |
void |
writeStartDocument() |
void |
writeStartDocument(String version) |
void |
writeStartDocument(String encoding,
String version) |
void |
writeStartElement(String localName) |
void |
writeStartElement(String namespaceURI,
String localName) |
void |
writeStartElement(String prefix,
String localName,
String namespaceURI) |
close, flush, getNamespaceContext, getPrefix, getProperty, setDefaultNamespace, setNamespaceContext, setPrefix, writeAttribute, writeAttribute, writeAttribute, writeDefaultNamespace, writeNamespacepublic IndentingXMLStreamWriter(XMLStreamWriter out)
public void setIndent(String indent)
IndentationIndentation.DEFAULT_INDENT. "\t" is a popular alternative.setIndent in interface Indentationpublic String getIndent()
IndentationgetIndent in interface Indentationpublic void setNewLine(String newLine)
IndentationIndentation.NORMAL_END_OF_LINE.
getLineSeparator()() is a popular
alternative.setNewLine in interface Indentationpublic static String getLineSeparator()
Indentation.NORMAL_END_OF_LINE if that fails.public String getNewLine()
IndentationgetNewLine in interface Indentationpublic void writeStartDocument()
throws XMLStreamException
writeStartDocument in interface XMLStreamWriterwriteStartDocument in class StreamWriterDelegateXMLStreamExceptionpublic void writeStartDocument(String version) throws XMLStreamException
writeStartDocument in interface XMLStreamWriterwriteStartDocument in class StreamWriterDelegateXMLStreamExceptionpublic void writeStartDocument(String encoding, String version) throws XMLStreamException
writeStartDocument in interface XMLStreamWriterwriteStartDocument in class StreamWriterDelegateXMLStreamExceptionpublic void writeDTD(String dtd) throws XMLStreamException
writeDTD in interface XMLStreamWriterwriteDTD in class StreamWriterDelegateXMLStreamExceptionpublic void writeProcessingInstruction(String target) throws XMLStreamException
writeProcessingInstruction in interface XMLStreamWriterwriteProcessingInstruction in class StreamWriterDelegateXMLStreamExceptionpublic void writeProcessingInstruction(String target, String data) throws XMLStreamException
writeProcessingInstruction in interface XMLStreamWriterwriteProcessingInstruction in class StreamWriterDelegateXMLStreamExceptionpublic void writeComment(String data) throws XMLStreamException
writeComment in interface XMLStreamWriterwriteComment in class StreamWriterDelegateXMLStreamExceptionpublic void writeEmptyElement(String localName) throws XMLStreamException
writeEmptyElement in interface XMLStreamWriterwriteEmptyElement in class StreamWriterDelegateXMLStreamExceptionpublic void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException
writeEmptyElement in interface XMLStreamWriterwriteEmptyElement in class StreamWriterDelegateXMLStreamExceptionpublic void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException
writeEmptyElement in interface XMLStreamWriterwriteEmptyElement in class StreamWriterDelegateXMLStreamExceptionpublic void writeStartElement(String localName) throws XMLStreamException
writeStartElement in interface XMLStreamWriterwriteStartElement in class StreamWriterDelegateXMLStreamExceptionpublic void writeStartElement(String namespaceURI, String localName) throws XMLStreamException
writeStartElement in interface XMLStreamWriterwriteStartElement in class StreamWriterDelegateXMLStreamExceptionpublic void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException
writeStartElement in interface XMLStreamWriterwriteStartElement in class StreamWriterDelegateXMLStreamExceptionpublic void writeCharacters(String text) throws XMLStreamException
writeCharacters in interface XMLStreamWriterwriteCharacters in class StreamWriterDelegateXMLStreamExceptionpublic void writeCharacters(char[] text,
int start,
int len)
throws XMLStreamException
writeCharacters in interface XMLStreamWriterwriteCharacters in class StreamWriterDelegateXMLStreamExceptionpublic void writeCData(String data) throws XMLStreamException
writeCData in interface XMLStreamWriterwriteCData in class StreamWriterDelegateXMLStreamExceptionpublic void writeEntityRef(String name) throws XMLStreamException
writeEntityRef in interface XMLStreamWriterwriteEntityRef in class StreamWriterDelegateXMLStreamExceptionpublic void writeEndElement()
throws XMLStreamException
writeEndElement in interface XMLStreamWriterwriteEndElement in class StreamWriterDelegateXMLStreamExceptionpublic void writeEndDocument()
throws XMLStreamException
writeEndDocument in interface XMLStreamWriterwriteEndDocument in class StreamWriterDelegateXMLStreamExceptionprotected void beforeMarkup()
protected void afterMarkup()
protected void afterData()
protected void beforeStartElement()
protected void afterStartElement()
protected void beforeEndElement()
protected void afterEndElement()
protected void afterEndDocument()
protected void writeNewLine(int indentation)
throws XMLStreamException
XMLStreamExceptionCopyright © 2020. All rights reserved.