public abstract class XMLOutput extends Object
Constructor and Description |
---|
XMLOutput() |
Modifier and Type | Method and Description |
---|---|
static String |
escape(String original)
Escapes certain characters inappropriate for textual output.
|
static String |
quote(String original,
boolean isAttribute)
Escapes certain characters inappropriate for XML content output.
|
String |
toXML(String indent,
String namespace)
Dumps the state of the current element as XML output.
|
void |
toXML(Writer stream,
String indent)
Convenience adaptor method invoking the equivalent of:
|
abstract void |
toXML(Writer stream,
String indent,
String namespace)
Dump the state of the current element as XML output.
|
void |
writeAttribute(Writer stream,
String key,
String value)
XML write helper method writes a quoted attribute onto a stream.
|
void |
writeAttribute2(Writer stream,
String key,
String value)
Saner XML write helper method writes a quoted attribute onto a
stream.
|
public static String escape(String original)
original
- is a string that needs to be quotedpublic static String quote(String original, boolean isAttribute)
original
- is a string that needs to be quotedisAttribute
- denotes an attributes value, if set to true.
If false, it denotes regular XML content outside of attributes.public void writeAttribute(Writer stream, String key, String value) throws IOException
stream
- is the stream to append tokey
- is the attribute including initial space, attribute name,
equals sign, and opening quote. The string passed as key must never
be null
.value
- is a string value, which will be put within the quotes
and which will be escaped. If the value is null, no action will be
takenIOException
- for stream errors.public void writeAttribute2(Writer stream, String key, String value) throws IOException
null
.stream
- is the stream to append tokey
- is the attribute identifier, and just that.value
- is a string value, which will be put within the quotes
and which will be escaped. If the value is null, no action will be
taken.IOException
- for stream errors.public String toXML(String indent, String namespace) throws IOException
Sibling classes which represent small leaf objects, and can return the necessary data more efficiently, are encouraged to overwrite this method.
indent
- is a String
of spaces used for pretty
printing. The initial amount of spaces should be an empty string.
The parameter is used internally for the recursive traversal.
If null, avoidable whitespaces in the output will be avoided.namespace
- is the XML schema namespace prefix. If neither
empty nor null, each element will be prefixed with this prefix,
and the root element will map the XML namespace.IOException
- when encountering an error constructing the
string.public void toXML(Writer stream, String indent) throws IOException
toXML( stream, indent, (String) null );
stream
- is a stream opened and ready for writing. This can also
be a string stream for efficient output.indent
- is a String
of spaces used for pretty
printing. The initial amount of spaces should be an empty string.
The parameter is used internally for the recursive traversal.
If a null
value is specified, no indentation nor
linefeeds will be generated.IOException
- if something fishy happens to the stream.toXML( Writer, String, String )
public abstract void toXML(Writer stream, String indent, String namespace) throws IOException
stream
- is a stream opened and ready for writing. This can also
be a string stream for efficient output.indent
- is a String
of spaces used for pretty
printing. The initial amount of spaces should be an empty string.
The parameter is used internally for the recursive traversal.
If a null
value is specified, no indentation nor
linefeeds will be generated.namespace
- is the XML schema namespace prefix. If neither
empty nor null, each element will be prefixed with this prefix, and
the root element will map the XML namespace. Use null
,
if you do not need an XML namespace.IOException
- if something fishy happens to the stream.BufferedWriter