Package org.apache.juneau.marshall.xml
Class XmlWriter<SELF extends XmlWriter<SELF>>
java.lang.Object
java.io.Writer
org.apache.juneau.marshall.serializer.SerializerWriter<SELF>
org.apache.juneau.marshall.xml.XmlWriter<SELF>
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
- Direct Known Subclasses:
BasicXmlWriter,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.marshall.serializer.SerializerWriter
maxIndent, out, quoteChar, trimStrings, uriResolver, useWhitespace -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionShortcut forattr(null , name, value,true );Shortcut forattr(null , name, value, valNeedsEncoding);Shortcut forattr(ns, name, value,true );Writes an attribute to the output:ns:name ='value' Same asattr(String, String, Object), except pass in aNamespaceobject 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' protected SELFWrites an attribute value to the output, optionally encoding it.ceTag()Closes an empty tag.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> 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 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()
-
Constructor Details
-
XmlWriter
protected 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.
-
XmlWriter
Copy constructor.- Parameters:
w- Writer being copied.
-
-
Method Details
-
attr
Same asattr(String, String, Object), except pass in aNamespaceobject for the namespace.- Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The attribute name.value- The attribute value. Encoded as described inattr(String, String, Object, boolean).- Returns:
- This object.
-
attr
Shortcut forattr(null , name, value,true );- Parameters:
name- The attribute name.value- The attribute value. Encoded as described inattr(String, String, Object, boolean).- Returns:
- This object.
-
attr
Shortcut forattr(null , name, value, valNeedsEncoding);- Parameters:
name- The attribute name.value- The attribute value.valNeedsEncoding- Iftrue , the attribute value will be encoded.- Returns:
- This object.
-
attr
Shortcut forattr(ns, name, value,true );- Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The attribute name.value- The attribute value. Encoded as described inattr(String, String, Object, boolean).- Returns:
- This object.
-
attr
Writes an attribute to the output:ns:name ='value' Encoding defends against markup injection: an unencoded value containing a quote character terminates the attribute early and lets the remainder of the value be interpreted as markup. Pass
false only for values that are already known to be safe attribute text.- Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The attribute name.value- The attribute value.valNeedsEncoding- Iftrue , the attribute value will be encoded.- Returns:
- This object.
-
attrUri
Writes an attribute with a URI value to the output:ns:name ='uri-value' - Parameters:
ns- The namespace. Can benull (no namespace prefix is written).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.
-
attrUri
Writes an attribute with a URI value to the output:ns:name ='uri-value' - Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The attribute name.value- The attribute value, convertible to a URI viatoString() - Returns:
- This object.
-
ceTag
Closes an empty tag.Shortcut for
append('/' ).append('->' );- Returns:
- This object.
-
cTag
Closes a tag.Shortcut for
append('->' );- 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.
-
eTag
Shortcut fori(indent).eTag(ns, name,false );- Parameters:
indent- The number of prefix tabs to add.ns- The namespace. Can benull (no namespace prefix is written).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 (no namespace prefix is written).name- The element name.needsEncoding- Iftrue , element name will be encoded.- Returns:
- This object.
-
eTag
Shortcut foreTag(null , name,false );- Parameters:
name- The element name.- Returns:
- This object.
-
eTag
Shortcut foreTag(ns, name,false );- Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The element name.- Returns:
- This object.
-
eTag
Writes an end tag to the output:</ns:name> - Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The element name.needsEncoding- Iftrue , element name will be encoded.- Returns:
- This object.
-
oAttr
Writes an open-ended attribute to the output:ns:name =- Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The attribute name.- Returns:
- This object.
-
oAttr
Writes an open-ended attribute to the output:ns:name =- Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The attribute 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.
-
oTag
Shortcut fori(indent).oTag(ns, name,false );- Parameters:
indent- The number of prefix tabs to add.ns- The namespace. Can benull (no namespace prefix is written).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 (no namespace prefix is written).name- The element name.needsEncoding- Iftrue , element name will be encoded.- Returns:
- This object.
-
oTag
Shortcut foroTag(null , name,false );- Parameters:
name- The element name.- Returns:
- This object.
-
oTag
Shortcut foroTag(ns, name,false );- Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The element name.- Returns:
- This object.
-
oTag
Writes an opening tag to the output:<ns:name - Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The element name.needsEncoding- Iftrue , element name will be encoded.- 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.
-
sTag
Shortcut fori(indent).sTag(ns, name,false );- Parameters:
indent- The number of prefix tabs to add.ns- The namespace. Can benull (no namespace prefix is written).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 (no namespace prefix is written).name- The element name.needsEncoding- Iftrue , element name will be encoded.- Returns:
- This object.
-
sTag
Shortcut forsTag(null , name,false );- Parameters:
name- The element name.- Returns:
- This object.
-
sTag
Shortcut forsTag(ns, name,false );- Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The element name.- Returns:
- This object.
-
sTag
Writes a start tag to the output:<ns:name> - Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The element name.needsEncoding- Iftrue , element name will be encoded.- 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,false );- Parameters:
indent- The number of prefix tabs to add.ns- The namespace. Can benull (no namespace prefix is written).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 (no namespace prefix is written).name- The element name.needsEncoding- Iftrue , element name will be encoded.- Returns:
- This object.
-
tag
Shortcut fortag(null , name,false );- Parameters:
name- The element name.- Returns:
- This object.
-
tag
Shortcut fortag(ns, name,false );- Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The element name.- Returns:
- This object.
-
tag
Writes a closed tag to the output:<ns:name/> - Parameters:
ns- The namespace. Can benull (no namespace prefix is written).name- The element name.needsEncoding- Iftrue , element name will be encoded.- 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_PWSorXmlFormat.TEXT_PWScontent.- 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.
-
toString
-
attrValue
Writes an attribute value to the output, optionally encoding it.- Parameters:
value- The attribute value.URIandURLvalues are resolved against the URI resolver first.needsEncoding- Iftrue , the value is encoded viaXmlUtils.encodeAttrValue(Writer, Object, boolean).- Returns:
- This object.
-