public class PrettyPrintWriter extends AbstractXmlWriter
By default, the chars & < > " ' \r
are escaped
and replaced with a suitable XML entity. To alter this behavior, override
the writeText(com.thoughtworks.xstream.core.util.QuickWriter, String)
and
writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter, String)
methods.
The XML specification requires XML parsers to drop CR characters completely. This implementation
will therefore use only a LF for line endings, never the platform encoding. You can overwrite the
getNewLine()
method for a different behavior.
Note: Depending on the XML version some characters cannot be written. Especially a 0
character is never valid in XML, neither directly nor as entity nor within CDATA. However, this writer
works by default in a quirks mode, where it will write any character at least as character entity (even
a null character). You may switch into XML_1_1 mode (which supports most characters) or XML_1_0
that does only support a very limited number of control characters. See XML specification for version
1.0 or
1.1. If a character is
not supported, a StreamException
is thrown. Select a proper parser implementation that
respects the version in the XML header (the Xpp3 parser will also read character entities of normally
invalid characters).
Modifier and Type | Field and Description |
---|---|
protected int |
depth |
static int |
XML_1_0 |
static int |
XML_1_1 |
static int |
XML_QUIRKS |
Constructor and Description |
---|
PrettyPrintWriter(Writer writer) |
PrettyPrintWriter(Writer writer,
char[] lineIndenter) |
PrettyPrintWriter(Writer writer,
char[] lineIndenter,
String newLine)
Deprecated.
As of 1.3
|
PrettyPrintWriter(Writer writer,
char[] lineIndenter,
String newLine,
XmlFriendlyReplacer replacer)
Deprecated.
As of 1.3
|
PrettyPrintWriter(Writer writer,
int mode) |
PrettyPrintWriter(Writer writer,
int mode,
char[] lineIndenter) |
PrettyPrintWriter(Writer writer,
int mode,
char[] lineIndenter,
NameCoder nameCoder) |
PrettyPrintWriter(Writer writer,
int mode,
char[] lineIndenter,
XmlFriendlyReplacer replacer)
Deprecated.
As of 1.4 use
PrettyPrintWriter(Writer, int, char[], NameCoder) instead |
PrettyPrintWriter(Writer writer,
int mode,
NameCoder nameCoder) |
PrettyPrintWriter(Writer writer,
int mode,
String lineIndenter) |
PrettyPrintWriter(Writer writer,
int mode,
XmlFriendlyReplacer replacer)
Deprecated.
As of 1.4 use
PrettyPrintWriter(Writer, int, NameCoder) instead |
PrettyPrintWriter(Writer writer,
NameCoder nameCoder) |
PrettyPrintWriter(Writer writer,
String lineIndenter) |
PrettyPrintWriter(Writer writer,
String lineIndenter,
String newLine)
Deprecated.
As of 1.3
|
PrettyPrintWriter(Writer writer,
XmlFriendlyReplacer replacer)
Deprecated.
As of 1.4 use
PrettyPrintWriter(Writer, NameCoder) instead. |
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(String key,
String value) |
void |
close()
Close the writer, if necessary.
|
void |
endNode() |
protected void |
endOfLine() |
void |
flush()
Flush the writer, if necessary.
|
protected String |
getNewLine()
Retrieve the line terminator.
|
void |
setValue(String text)
Write the value (text content) of the current node.
|
void |
startNode(String name) |
void |
startNode(String name,
Class clazz) |
protected void |
writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter writer,
String text) |
protected void |
writeText(com.thoughtworks.xstream.core.util.QuickWriter writer,
String text) |
escapeXmlName
encodeAttribute, encodeNode, underlyingWriter
public static int XML_QUIRKS
public static int XML_1_0
public static int XML_1_1
protected int depth
public PrettyPrintWriter(Writer writer, char[] lineIndenter, String newLine, XmlFriendlyReplacer replacer)
public PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter, NameCoder nameCoder)
public PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter, XmlFriendlyReplacer replacer)
PrettyPrintWriter(Writer, int, char[], NameCoder)
insteadpublic PrettyPrintWriter(Writer writer, char[] lineIndenter, String newLine)
public PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter)
public PrettyPrintWriter(Writer writer, char[] lineIndenter)
public PrettyPrintWriter(Writer writer, String lineIndenter, String newLine)
public PrettyPrintWriter(Writer writer, int mode, XmlFriendlyReplacer replacer)
PrettyPrintWriter(Writer, int, NameCoder)
insteadpublic PrettyPrintWriter(Writer writer, XmlFriendlyReplacer replacer)
PrettyPrintWriter(Writer, NameCoder)
instead.public PrettyPrintWriter(Writer writer, int mode)
public PrettyPrintWriter(Writer writer)
public void startNode(String name)
public void startNode(String name, Class clazz)
AbstractWriter
startNode
in interface ExtendedHierarchicalStreamWriter
startNode
in class AbstractWriter
public void setValue(String text)
HierarchicalStreamWriter
protected void writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter writer, String text)
protected void writeText(com.thoughtworks.xstream.core.util.QuickWriter writer, String text)
public void endNode()
protected void endOfLine()
public void flush()
HierarchicalStreamWriter
public void close()
HierarchicalStreamWriter
protected String getNewLine()
Copyright © 2004–2016 XStream. All rights reserved.