SimpleXmlWriter
,
where open(String, Object...)
is renamed to SimpleXmlWriter.begin(String, Object...)
and close()
to SimpleXmlWriter.end()
, which allows to make the class
closable.@Deprecated
public class SimpleXmlWriter
extends java.lang.Object
This writer makes creation of simple XML documents without advanced features simple. Use the following to create simple XML:
element(String, Object...)
method writes an empty element
which is already closed with the given attributes' name-value pairs.
open(String, Object...)
method writes an opening element
with the given attributes' name-value pairs.
close()
method closes the element created by the latest
open(String, Object...)
call.
finish()
method closes all open elements.
comment(String)
method inserts a comment with the given text.
text(Object)
method inserts the given text, taking care of
escaping.
textf(String, Object...)
method does the same, but allows
formatting like String.format(String, Object...)
.
cdata(String)
method inserts the given text in raw
form as a CDATA section.
nl()
method can be used to insert a newline,
see also the comments on automatic wrapping below.
expand(byte[])
inserts binary data as 2-digit-per-byte
hexadecimal numbers.
expandBase64(byte[])
inserts binary data in base64 encoding.
expand(byte[], int)
method can be used to format binary
data as 2-digit-per-byte hexadecimal numbers, and can be used with
either the text(Object)
method or as attribute value (in the
latter case best with columns
set to 0
).
Automatic wrapping and indentation of hierarchy levels can be switched on
by using constructor which accept an indentation
parameter with
a non-negative indentation value.
A value of 0
switches auto-wrapping on, starting each opening tag
on a new line. A value greater than zero will also indent each sub level
by the given number of blanks. A negative value will switch both auto-wrapping
and indentation off.
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoWrap
Deprecated.
Is automatic wrapping enabled?
|
protected StringCollector |
collector
Deprecated.
Collector used for output text collection.
|
static java.lang.String |
DEFAULT_ENCODING
Deprecated.
Default encoding in XML header.
|
protected java.lang.String |
indentation
Deprecated.
Use as indentation if non-
null . |
protected java.util.Locale |
locale
Deprecated.
Locale to be used when formatting.
|
Constructor and Description |
---|
SimpleXmlWriter(java.util.Locale locale,
StringCollector collector)
Deprecated.
Constructor.
|
SimpleXmlWriter(java.util.Locale locale,
StringCollector collector,
int indentation)
Deprecated.
Constructor.
|
SimpleXmlWriter(java.util.Locale locale,
StringCollector collector,
java.lang.String preamble)
Deprecated.
Constructor.
|
SimpleXmlWriter(java.util.Locale locale,
StringCollector collector,
java.lang.String preamble,
int indentation)
Deprecated.
Constructor.
|
SimpleXmlWriter(StringCollector collector)
Deprecated.
Constructor.
|
SimpleXmlWriter(StringCollector collector,
int indentation)
Deprecated.
Constructor.
|
SimpleXmlWriter(StringCollector collector,
java.lang.String preamble)
Deprecated.
Constructor.
|
SimpleXmlWriter(StringCollector collector,
java.lang.String preamble,
int indentation)
Deprecated.
Constructor.
|
Modifier and Type | Method and Description |
---|---|
SimpleXmlWriter |
cdata(java.lang.String text)
Deprecated.
Outputs the raw text as CDATA section.
|
SimpleXmlWriter |
close()
Deprecated.
Close the latest open element.
|
SimpleXmlWriter |
comment(java.lang.String comment)
Deprecated.
Add a comment.
|
SimpleXmlWriter |
element(java.lang.String tag,
java.lang.Object... attributes)
Deprecated.
Writes an empty element.
|
SimpleXmlWriter |
expand(byte[] data)
Deprecated.
Convert data into hex code and add it as text.
|
static java.lang.String |
expand(byte[] data,
int columns)
Deprecated.
Expand an array of bytes into a hex string.
|
SimpleXmlWriter |
expandBase64(byte[] data)
Deprecated.
Convert data into hex code and add it as text.
|
void |
finish()
Deprecated.
Close all open elements.
|
static java.lang.String |
getDefaultPreamble()
Deprecated.
Get the default XML preamble with UTF-8 encoding.
|
java.lang.String |
getIndentation()
Deprecated.
Get the indentation.
|
java.util.Locale |
getLocale()
Deprecated.
Get the locale used for formatting text.
|
static java.lang.String |
getPreamble(java.lang.String encoding)
Deprecated.
Get an XML preamble with the given encoding.
|
boolean |
isAutoWrap()
Deprecated.
Is automatic wrapping enabled?
|
SimpleXmlWriter |
nl()
Deprecated.
Add a newline.
|
SimpleXmlWriter |
open(java.lang.String tag,
java.lang.Object... attributes)
Deprecated.
Write the opening tag of an element.
|
SimpleXmlWriter |
text(java.lang.Object text)
Deprecated.
Add text outside of tags.
|
SimpleXmlWriter |
textf(java.lang.String format,
java.lang.Object... args)
Deprecated.
Add formatted text outside of tags.
|
public static final java.lang.String DEFAULT_ENCODING
@NotNull protected final StringCollector collector
protected final boolean autoWrap
@Nullable protected final java.lang.String indentation
null
.@NotNull protected final java.util.Locale locale
public SimpleXmlWriter(@NotNull StringCollector collector)
default preamble
,
default locale, no indentation, and no automatic wrapping,collector
- string collector to which the XML output is writtenOutputStreamStringCollector
,
TextStringCollector
public SimpleXmlWriter(@NotNull java.util.Locale locale, @NotNull StringCollector collector)
default preamble
,
no indentation, and no automatic wrapping,locale
- locale used for text formatting in textf(String, Object...)
collector
- string collector to which the XML output is writtenOutputStreamStringCollector
,
TextStringCollector
public SimpleXmlWriter(@NotNull StringCollector collector, @Nullable java.lang.String preamble)
collector
- string collector to which the XML output is writtenpreamble
- preamble written at the start, if null
no preamble is writtenOutputStreamStringCollector
,
TextStringCollector
public SimpleXmlWriter(@NotNull java.util.Locale locale, @NotNull StringCollector collector, @Nullable java.lang.String preamble)
locale
- locale used for text formatting in textf(String, Object...)
collector
- string collector to which the XML output is writtenpreamble
- preamble written at the start, if null
no preamble is writtenOutputStreamStringCollector
,
TextStringCollector
public SimpleXmlWriter(@NotNull StringCollector collector, int indentation)
default preamble
.collector
- string collector to which the XML output is writtenindentation
- if 0
or more automatic newlines will be inserted and nested levels will be indented
by the given number of spacespublic SimpleXmlWriter(@NotNull java.util.Locale locale, @NotNull StringCollector collector, int indentation)
default preamble
.locale
- locale used for text formatting in textf(String, Object...)
collector
- string collector to which the XML output is writtenindentation
- if 0
or more automatic newlines will be inserted and nested levels will be indented
by the given number of spacespublic SimpleXmlWriter(@NotNull StringCollector collector, @Nullable java.lang.String preamble, int indentation)
collector
- string collector to which the XML output is writtenpreamble
- preamble to be written at the beginning of the output, use null
for no preambleindentation
- if 0
or more automatic newlines will be inserted and nested levels will be indented
by the given number of spacesgetDefaultPreamble()
,
getPreamble(String)
public SimpleXmlWriter(@NotNull java.util.Locale locale, @NotNull StringCollector collector, @Nullable java.lang.String preamble, int indentation)
locale
- locale used for text formatting in textf(String, Object...)
collector
- string collector to which the XML output is writtenpreamble
- preamble to be written at the beginning of the output, use null
for no preambleindentation
- if 0
or more automatic newlines will be inserted and nested levels will be indented
by the given number of spacesgetDefaultPreamble()
,
getPreamble(String)
public boolean isAutoWrap()
true
: automatic wrapping is enabledfalse
: automatic wrapping is disabled@NotNull public java.lang.String getIndentation()
@NotNull public java.util.Locale getLocale()
textf(String, Object...)
@NotNull public static java.lang.String getDefaultPreamble()
@NotNull public static java.lang.String getPreamble(@NotNull java.lang.String encoding)
encoding
- encoding@NotNull public SimpleXmlWriter open(@NotNull java.lang.String tag, java.lang.Object... attributes)
tag
- element tagattributes
- attributes, always in pairs of attribute name
and attribute value, values will be escaped@NotNull public SimpleXmlWriter close()
java.util.EmptyStackException
- if closing although no element is open@NotNull public SimpleXmlWriter comment(@NotNull java.lang.String comment)
comment
- comment to add@NotNull public SimpleXmlWriter expand(@NotNull byte[] data)
data
- data to add@NotNull public static java.lang.String expand(@NotNull byte[] data, int columns)
data
- data to expandcolumns
- columns of hex digits of returned string before a line break is inserted.
If 0
or less no break is inserted.@NotNull public SimpleXmlWriter expandBase64(@NotNull byte[] data)
data
- data to add@NotNull public SimpleXmlWriter element(@NotNull java.lang.String tag, java.lang.Object... attributes)
tag
- element tagattributes
- attributes, always in pairs of attribute name
and attribute value, values will be escaped@NotNull public SimpleXmlWriter text(@NotNull java.lang.Object text)
text
- text to add@NotNull public SimpleXmlWriter textf(@NotNull java.lang.String format, @NotNull java.lang.Object... args)
String.format(String, Object...)
using the locale
set via the constructor.format
- format stringargs
- arguments for the format string@NotNull public SimpleXmlWriter nl()
@NotNull public SimpleXmlWriter cdata(@NotNull java.lang.String text)
text
- text to be output, not escaped in any formpublic void finish()