Package org.apache.juneau.xml
Class XmlWriter
java.lang.Object
java.io.Writer
org.apache.juneau.serializer.SerializerWriter
org.apache.juneau.xml.XmlWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
- Direct Known Subclasses:
HtmlWriter
Specialized writer for serializing XML.
Notes:
- This class is not intended for external use.
See Also:
-
Field Summary
Fields inherited from class org.apache.juneau.serializer.SerializerWriter
maxIndent, out, quoteChar, trimStrings, uriResolver, useWhitespace
-
Constructor Summary
ConstructorDescriptionXmlWriter
(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, char quoteChar, UriResolver uriResolver, boolean enableNs, Namespace defaultNamespace) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionappend
(char c) append
(int indent, char c) Writes an indent (if theuseWhitespace
setting is enabled), followed by text.Writes an indent (if theuseWhitespace
setting is enabled), followed by text.Writes the specified text to the writer if it isn'tnull .Writes the specified text to the writer if it isn'tnull .Writes an indent (if theuseWhitespace
setting is enabled), followed by text, followed by a newline (if theuseWhitespace
setting is enabled).Writes the specified text followed by a newline (if theuseWhitespace
setting is enabled).Shortcut forattr(
null , name, value,false );Shortcut forattr(
null , name, value,false );Shortcut forattr(ns, name, value,
false );Writes an attribute to the output:ns:name ='value' Same asattr(String, String, Object)
, except pass in aNamespace
object for the namespace.Append an attribute with a URI value.Writes an attribute with a URI value to the output:ns:name ='uri-value' Writes an attribute with a URI value to the output:ns:name ='uri-value' ceTag()
Closes an empty tag.cr
(int depth) Performs a carriage return.cre
(int depth) Performs a carriage return at the end of a line.cTag()
Closes a tag.Shortcut fori(indent).eTag(
null , name,false );Shortcut fori(indent).eTag(ns, name,
false );Shortcut fori(indent).eTag(ns, name, needsEncoding); Shortcut foreTag(
null , name,false );Shortcut foreTag(ns, name,
false );Writes an end tag to the output:</ns:name> i
(int indent) Writes an indent to the writer if theuseWhitespace
setting is enabled.ie
(int indent) Writes an end-of-line indent to the writer if theuseWhitespace
setting is enabled.nl
(int indent) Writes a newline to the writer if theuseWhitespace
setting is enabled.Writes an open-ended attribute to the output:ns:name =Writes an open-ended attribute to the output:ns:name =Shortcut fori(indent).oTag(
null , name,false );Shortcut fori(indent).oTag(ns, name,
false );Shortcut fori(indent).oTag(ns, name, needsEncoding); Shortcut foroTag(
null , name,false );Shortcut foroTag(ns, name,
false );Writes an opening tag to the output:<ns:name q()
Adds the quote character specified by thequoteChar
setting to the output.s()
Adds a whitespace character to the output if theuseWhitespace
setting is enabled.Shortcut fori(indent).sTag(
null , name,false );Shortcut fori(indent).sTag(ns, name,
false );Shortcut fori(indent).sTag(ns, name, needsEncoding); Shortcut forsTag(
null , name,false );Shortcut forsTag(ns, name,
false );Writes a start tag to the output:<ns:name> Shortcut fori(indent).tag(
null , name,false );Shortcut fori(indent).tag(ns, name,
false );Shortcut fori(indent).tag(ns, name, needsEncoding); Shortcut fortag(
null , name,false );Shortcut fortag(ns, name,
false );Writes a closed tag to the output:<ns:name/> Shortcut for callingtext(o,
false );Serializes and encodes the specified object as valid XML text.Same astext(Object)
but treats the value as a URL to resolved then serialized.toString()
w
(char c) Writes the specified character to the writer.Writes the specified string to the writer.
-
Constructor Details
-
XmlWriter
public XmlWriter(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, char quoteChar, UriResolver uriResolver, boolean enableNs, Namespace defaultNamespace) Constructor.- Parameters:
out
- The wrapped writer.useWhitespace
- Iftrue XML elements will be indented.maxIndent
- The maximum indentation level.trimStrings
- Iftrue , strings should be trimmed before they're serialized.quoteChar
- The quote character to use for attributes. Should be'\'' or'"' .uriResolver
- The URI resolver for resolving URIs to absolute or root-relative form.enableNs
- Flag to indicate if XML namespaces are enabled.defaultNamespace
- The default namespace if XML namespaces are enabled.
-
-
Method Details
-
oTag
Writes an opening tag to the output:<ns:name - Parameters:
ns
- The namespace. Can benull .name
- The element name.needsEncoding
- Iftrue , element name will be encoded.- Returns:
- This object.
-
oTag
Shortcut foroTag(ns, name,
false );- Parameters:
ns
- The namespace. Can benull .name
- The element name.- Returns:
- This object.
-
oTag
Shortcut foroTag(
null , name,false );- Parameters:
name
- The element name.- Returns:
- This object.
-
oTag
Shortcut fori(indent).oTag(ns, name, needsEncoding); - Parameters:
indent
- The number of prefix tabs to add.ns
- The namespace. Can benull .name
- The element name.needsEncoding
- Iftrue , element name will be encoded.- Returns:
- This object.
-
oTag
Shortcut fori(indent).oTag(ns, name,
false );- Parameters:
indent
- The number of prefix tabs to add.ns
- The namespace. Can benull .name
- The element name.- Returns:
- This object.
-
oTag
Shortcut fori(indent).oTag(
null , name,false );- Parameters:
indent
- The number of prefix tabs to add.name
- The element name.- Returns:
- This object.
-
cTag
Closes a tag.Shortcut for
append(
'->' );- Returns:
- This object.
-
ceTag
Closes an empty tag.Shortcut for
append(
'/' ).append('->' );- Returns:
- This object.
-
tag
Writes a closed tag to the output:<ns:name/> - Parameters:
ns
- The namespace. Can benull .name
- The element name.needsEncoding
- Iftrue , element name will be encoded.- Returns:
- This object.
-
tag
Shortcut fortag(ns, name,
false );- Parameters:
ns
- The namespace. Can benull .name
- The element name.- Returns:
- This object.
-
tag
Shortcut fortag(
null , name,false );- Parameters:
name
- The element name.- Returns:
- This object.
-
tag
Shortcut fori(indent).tag(
null , name,false );- Parameters:
indent
- The number of prefix tabs to add.name
- The element name.- Returns:
- This object.
-
tag
Shortcut fori(indent).tag(ns, name, needsEncoding); - Parameters:
indent
- The number of prefix tabs to add.ns
- The namespace. Can benull .name
- The element name.needsEncoding
- Iftrue , element name will be encoded.- Returns:
- This object.
-
tag
Shortcut fori(indent).tag(ns, name,
false );- Parameters:
indent
- The number of prefix tabs to add.ns
- The namespace. Can benull .name
- The element name.- Returns:
- This object.
-
sTag
Writes a start tag to the output:<ns:name> - Parameters:
ns
- The namespace. Can benull .name
- The element name.needsEncoding
- Iftrue , element name will be encoded.- Returns:
- This object.
-
sTag
Shortcut forsTag(ns, name,
false );- Parameters:
ns
- The namespace. Can benull .name
- The element name.- Returns:
- This object.
-
sTag
Shortcut forsTag(
null , name,false );- Parameters:
name
- The element name.- Returns:
- This object.
-
sTag
Shortcut fori(indent).sTag(ns, name, needsEncoding); - Parameters:
indent
- The number of prefix tabs to add.ns
- The namespace. Can benull .name
- The element name.needsEncoding
- Iftrue , element name will be encoded.- Returns:
- This object.
-
sTag
Shortcut fori(indent).sTag(ns, name,
false );- Parameters:
indent
- The number of prefix tabs to add.ns
- The namespace. Can benull .name
- The element name.- Returns:
- This object.
-
sTag
Shortcut fori(indent).sTag(
null , name,false );- Parameters:
indent
- The number of prefix tabs to add.name
- The element name.- Returns:
- This object.
-
eTag
Writes an end tag to the output:</ns:name> - Parameters:
ns
- The namespace. Can benull .name
- The element name.needsEncoding
- Iftrue , element name will be encoded.- Returns:
- This object.
-
eTag
Shortcut foreTag(ns, name,
false );- Parameters:
ns
- The namespace. Can benull .name
- The element name.- Returns:
- This object.
-
eTag
Shortcut foreTag(
null , name,false );- Parameters:
name
- The element name.- Returns:
- This object.
-
eTag
Shortcut fori(indent).eTag(ns, name, needsEncoding); - Parameters:
indent
- The number of prefix tabs to add.ns
- The namespace. Can benull .name
- The element name.needsEncoding
- Iftrue , element name will be encoded.- Returns:
- This object.
-
eTag
Shortcut fori(indent).eTag(ns, name,
false );- Parameters:
indent
- The number of prefix tabs to add.ns
- The namespace. Can benull .name
- The element name.- Returns:
- This object.
-
eTag
Shortcut fori(indent).eTag(
null , name,false );- Parameters:
indent
- The number of prefix tabs to add.name
- The element name.- Returns:
- This object.
-
attr
Writes an attribute to the output:ns:name ='value' - Parameters:
ns
- The namespace. Can benull .name
- The attribute name.value
- The attribute value.valNeedsEncoding
- Iftrue , attribute name will be encoded.- Returns:
- This object.
-
attr
Shortcut forattr(
null , name, value,false );- Parameters:
name
- The attribute name.value
- The attribute value.valNeedsEncoding
- Iftrue , attribute name will be encoded.- Returns:
- This object.
-
attr
Shortcut forattr(ns, name, value,
false );- Parameters:
ns
- The namespace. Can benull .name
- The attribute name.value
- The attribute value.- Returns:
- This object.
-
attr
Same asattr(String, String, Object)
, except pass in aNamespace
object for the namespace.- Parameters:
ns
- The namespace. Can benull .name
- The attribute name.value
- The attribute value.- Returns:
- This object.
-
attr
Shortcut forattr(
null , name, value,false );- Parameters:
name
- The attribute name.value
- The attribute value.- Returns:
- This object.
-
oAttr
Writes an open-ended attribute to the output:ns:name =- Parameters:
ns
- The namespace. Can benull .name
- The attribute name.- Returns:
- This object.
-
oAttr
Writes an open-ended attribute to the output:ns:name =- Parameters:
ns
- The namespace. Can benull .name
- The attribute name.- Returns:
- This object.
-
attrUri
Writes an attribute with a URI value to the output:ns:name ='uri-value' - Parameters:
ns
- The namespace. Can benull .name
- The attribute name.value
- The attribute value, convertible to a URI viatoString() - Returns:
- This object.
-
attrUri
Writes an attribute with a URI value to the output:ns:name ='uri-value' - Parameters:
ns
- The namespace. Can benull .name
- The attribute name.value
- The attribute value, convertible to a URI viatoString() - Returns:
- This object.
-
attrUri
Append an attribute with a URI value.- Parameters:
name
- The attribute name.value
- The attribute value. Can be any object whosetoString() method returns a URI.- Returns:
- This object.
-
text
Shortcut for callingtext(o,
false );- Parameters:
value
- The object being serialized.- Returns:
- This object.
-
text
Serializes and encodes the specified object as valid XML text.- Parameters:
value
- The object being serialized.preserveWhitespace
- Iftrue , then we're serializingXmlFormat.MIXED_PWS
orXmlFormat.TEXT_PWS
content.- Returns:
- This object.
-
textUri
Same astext(Object)
but treats the value as a URL to resolved then serialized.- Parameters:
value
- The object being serialized.- Returns:
- This object.
-
cr
Description copied from class:SerializerWriter
Performs a carriage return.Adds a newline and the specified number of tabs (if the
useWhitespace
setting is enabled) to the output.- Overrides:
cr
in classSerializerWriter
- Parameters:
depth
- The indentation.- Returns:
- This object.
-
cre
Description copied from class:SerializerWriter
Performs a carriage return at the end of a line.Adds a newline and the specified number of tabs (if the
useWhitespace
setting is enabled) to the output.- Overrides:
cre
in classSerializerWriter
- Parameters:
depth
- The indentation.- Returns:
- This object.
-
appendln
Description copied from class:SerializerWriter
Writes an indent (if theuseWhitespace
setting is enabled), followed by text, followed by a newline (if theuseWhitespace
setting is enabled).- Overrides:
appendln
in classSerializerWriter
- Parameters:
indent
- The number of tabs to indent.text
- The text to write.- Returns:
- This object.
-
appendln
Description copied from class:SerializerWriter
Writes the specified text followed by a newline (if theuseWhitespace
setting is enabled).- Overrides:
appendln
in classSerializerWriter
- Parameters:
text
- The text to write.- Returns:
- This object.
-
append
Description copied from class:SerializerWriter
Writes an indent (if theuseWhitespace
setting is enabled), followed by text.- Overrides:
append
in classSerializerWriter
- Parameters:
indent
- The number of tabs to indent.text
- The text to write.- Returns:
- This object.
-
append
Description copied from class:SerializerWriter
Writes an indent (if theuseWhitespace
setting is enabled), followed by text.- Overrides:
append
in classSerializerWriter
- Parameters:
indent
- The number of tabs to indent.c
- The character to write.- Returns:
- This object.
-
s
Description copied from class:SerializerWriter
Adds a whitespace character to the output if theuseWhitespace
setting is enabled.- Overrides:
s
in classSerializerWriter
- Returns:
- This object.
-
q
Description copied from class:SerializerWriter
Adds the quote character specified by thequoteChar
setting to the output.- Overrides:
q
in classSerializerWriter
- Returns:
- This object.
-
i
Description copied from class:SerializerWriter
Writes an indent to the writer if theuseWhitespace
setting is enabled.- Overrides:
i
in classSerializerWriter
- Parameters:
indent
- The number of tabs to indent.- Returns:
- This object.
-
ie
Description copied from class:SerializerWriter
Writes an end-of-line indent to the writer if theuseWhitespace
setting is enabled.- Overrides:
ie
in classSerializerWriter
- Parameters:
indent
- The number of tabs to indent.- Returns:
- This object.
-
nl
Description copied from class:SerializerWriter
Writes a newline to the writer if theuseWhitespace
setting is enabled.- Overrides:
nl
in classSerializerWriter
- Parameters:
indent
- The current indentation level.- Returns:
- This object.
-
append
Description copied from class:SerializerWriter
Writes the specified text to the writer if it isn'tnull .- Overrides:
append
in classSerializerWriter
- Parameters:
text
- The text to write.- Returns:
- This object.
-
append
Description copied from class:SerializerWriter
Writes the specified text to the writer if it isn'tnull .- Overrides:
append
in classSerializerWriter
- Parameters:
text
- The text to write.- Returns:
- This object.
-
append
- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classSerializerWriter
-
w
Description copied from class:SerializerWriter
Writes the specified character to the writer.- Overrides:
w
in classSerializerWriter
- Parameters:
c
- The character to write.- Returns:
- This object.
-
w
Description copied from class:SerializerWriter
Writes the specified string to the writer.- Overrides:
w
in classSerializerWriter
- Parameters:
s
- The string to write.- Returns:
- This object.
-
toString
-