|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavanet.staxutils.helpers.EventWriterDelegate
javanet.staxutils.IndentingXMLEventWriter
public class IndentingXMLEventWriter
A filter that indents an XML stream. To apply it, construct a filter that
contains another XMLEventWriter, which you pass to the constructor.
Then call methods of the filter instead of the contained stream. For example:
XMLEventWriterstream = ... stream = newIndentingXMLEventWriter(stream); stream.add(...);
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.
| Field Summary |
|---|
| Fields inherited from class javanet.staxutils.helpers.EventWriterDelegate |
|---|
out |
| Fields inherited from interface javanet.staxutils.Indentation |
|---|
DEFAULT_INDENT, NORMAL_END_OF_LINE |
| Constructor Summary | |
|---|---|
IndentingXMLEventWriter(XMLEventWriter out)
|
|
| Method Summary | |
|---|---|
void |
add(XMLEvent event)
|
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. |
| Methods inherited from class javanet.staxutils.helpers.EventWriterDelegate |
|---|
add, close, flush, getNamespaceContext, getPrefix, setDefaultNamespace, setNamespaceContext, setPrefix |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public IndentingXMLEventWriter(XMLEventWriter out)
| Method Detail |
|---|
public void setIndent(String indent)
IndentationIndentation.DEFAULT_INDENT. "\t" is a popular alternative.
setIndent in interface Indentationpublic void setNewLine(String newLine)
IndentationIndentation.NORMAL_END_OF_LINE.
IndentingXMLStreamWriter.getLineSeparator()() is a popular
alternative.
setNewLine in interface Indentationpublic String getIndent()
Indentation
getIndent in interface Indentationpublic String getNewLine()
Indentation
getNewLine in interface Indentationpublic static String getLineSeparator()
Indentation.NORMAL_END_OF_LINE if that fails.
public void add(XMLEvent event)
throws XMLStreamException
add in interface XMLEventConsumeradd in interface XMLEventWriteradd in class EventWriterDelegateXMLStreamExceptionprotected void beforeMarkup()
protected void afterMarkup()
protected void afterData()
protected void beforeStartElement()
protected void afterStartElement()
protected void beforeEndElement()
protected void afterEndElement()
protected void afterEndDocument()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||