Class XmlWriter

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
Direct Known Subclasses:
HtmlWriter

public class XmlWriter extends SerializerWriter
Specialized writer for serializing XML.
Notes:
  • This class is not intended for external use.
See Also:
  • 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 - If true XML elements will be indented.
      maxIndent - The maximum indentation level.
      trimStrings - If true, 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

      public XmlWriter oTag(String ns, String name, boolean needsEncoding)
      Writes an opening tag to the output: <ns:name
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • oTag

      public XmlWriter oTag(String ns, String name)
      Shortcut for oTag(ns, name, false);
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • oTag

      public XmlWriter oTag(String name)
      Shortcut for oTag(null, name, false);
      Parameters:
      name - The element name.
      Returns:
      This object.
    • oTag

      public XmlWriter oTag(int indent, String ns, String name, boolean needsEncoding)
      Shortcut for i(indent).oTag(ns, name, needsEncoding);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • oTag

      public XmlWriter oTag(int indent, String ns, String name)
      Shortcut for i(indent).oTag(ns, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • oTag

      public XmlWriter oTag(int indent, String name)
      Shortcut for i(indent).oTag(null, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • cTag

      public XmlWriter cTag()
      Closes a tag.

      Shortcut for append('->');

      Returns:
      This object.
    • ceTag

      public XmlWriter ceTag()
      Closes an empty tag.

      Shortcut for append('/').append('->');

      Returns:
      This object.
    • tag

      public XmlWriter tag(String ns, String name, boolean needsEncoding)
      Writes a closed tag to the output: <ns:name/>
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • tag

      public XmlWriter tag(String ns, String name)
      Shortcut for tag(ns, name, false);
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • tag

      public XmlWriter tag(String name)
      Shortcut for tag(null, name, false);
      Parameters:
      name - The element name.
      Returns:
      This object.
    • tag

      public XmlWriter tag(int indent, String name)
      Shortcut for i(indent).tag(null, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • tag

      public XmlWriter tag(int indent, String ns, String name, boolean needsEncoding)
      Shortcut for i(indent).tag(ns, name, needsEncoding);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • tag

      public XmlWriter tag(int indent, String ns, String name)
      Shortcut for i(indent).tag(ns, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • sTag

      public XmlWriter sTag(String ns, String name, boolean needsEncoding)
      Writes a start tag to the output: <ns:name>
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • sTag

      public XmlWriter sTag(String ns, String name)
      Shortcut for sTag(ns, name, false);
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • sTag

      public XmlWriter sTag(String name)
      Shortcut for sTag(null, name, false);
      Parameters:
      name - The element name.
      Returns:
      This object.
    • sTag

      public XmlWriter sTag(int indent, String ns, String name, boolean needsEncoding)
      Shortcut for i(indent).sTag(ns, name, needsEncoding);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • sTag

      public XmlWriter sTag(int indent, String ns, String name)
      Shortcut for i(indent).sTag(ns, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • sTag

      public XmlWriter sTag(int indent, String name)
      Shortcut for i(indent).sTag(null, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • eTag

      public XmlWriter eTag(String ns, String name, boolean needsEncoding)
      Writes an end tag to the output: </ns:name>
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • eTag

      public XmlWriter eTag(String ns, String name)
      Shortcut for eTag(ns, name, false);
      Parameters:
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • eTag

      public XmlWriter eTag(String name)
      Shortcut for eTag(null, name, false);
      Parameters:
      name - The element name.
      Returns:
      This object.
    • eTag

      public XmlWriter eTag(int indent, String ns, String name, boolean needsEncoding)
      Shortcut for i(indent).eTag(ns, name, needsEncoding);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      needsEncoding - If true, element name will be encoded.
      Returns:
      This object.
    • eTag

      public XmlWriter eTag(int indent, String ns, String name)
      Shortcut for i(indent).eTag(ns, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      ns - The namespace. Can be null.
      name - The element name.
      Returns:
      This object.
    • eTag

      public XmlWriter eTag(int indent, String name)
      Shortcut for i(indent).eTag(null, name, false);
      Parameters:
      indent - The number of prefix tabs to add.
      name - The element name.
      Returns:
      This object.
    • attr

      public XmlWriter attr(String ns, String name, Object value, boolean valNeedsEncoding)
      Writes an attribute to the output: ns:name='value'
      Parameters:
      ns - The namespace. Can be null.
      name - The attribute name.
      value - The attribute value.
      valNeedsEncoding - If true, attribute name will be encoded.
      Returns:
      This object.
    • attr

      public XmlWriter attr(String name, Object value, boolean valNeedsEncoding)
      Shortcut for attr(null, name, value, false);
      Parameters:
      name - The attribute name.
      value - The attribute value.
      valNeedsEncoding - If true, attribute name will be encoded.
      Returns:
      This object.
    • attr

      public XmlWriter attr(String ns, String name, Object value)
      Shortcut for attr(ns, name, value, false);
      Parameters:
      ns - The namespace. Can be null.
      name - The attribute name.
      value - The attribute value.
      Returns:
      This object.
    • attr

      public XmlWriter attr(Namespace ns, String name, Object value)
      Same as attr(String, String, Object), except pass in a Namespace object for the namespace.
      Parameters:
      ns - The namespace. Can be null.
      name - The attribute name.
      value - The attribute value.
      Returns:
      This object.
    • attr

      public XmlWriter attr(String name, Object value)
      Shortcut for attr(null, name, value, false);
      Parameters:
      name - The attribute name.
      value - The attribute value.
      Returns:
      This object.
    • oAttr

      public XmlWriter oAttr(String ns, String name)
      Writes an open-ended attribute to the output: ns:name=
      Parameters:
      ns - The namespace. Can be null.
      name - The attribute name.
      Returns:
      This object.
    • oAttr

      public XmlWriter oAttr(Namespace ns, String name)
      Writes an open-ended attribute to the output: ns:name=
      Parameters:
      ns - The namespace. Can be null.
      name - The attribute name.
      Returns:
      This object.
    • attrUri

      public XmlWriter attrUri(Namespace ns, String name, Object value)
      Writes an attribute with a URI value to the output: ns:name='uri-value'
      Parameters:
      ns - The namespace. Can be null.
      name - The attribute name.
      value - The attribute value, convertible to a URI via toString()
      Returns:
      This object.
    • attrUri

      public XmlWriter attrUri(String ns, String name, Object value)
      Writes an attribute with a URI value to the output: ns:name='uri-value'
      Parameters:
      ns - The namespace. Can be null.
      name - The attribute name.
      value - The attribute value, convertible to a URI via toString()
      Returns:
      This object.
    • attrUri

      public XmlWriter attrUri(String name, Object value)
      Append an attribute with a URI value.
      Parameters:
      name - The attribute name.
      value - The attribute value. Can be any object whose toString() method returns a URI.
      Returns:
      This object.
    • text

      public XmlWriter text(Object value)
      Shortcut for calling text(o, false);
      Parameters:
      value - The object being serialized.
      Returns:
      This object.
    • text

      public XmlWriter text(Object value, boolean preserveWhitespace)
      Serializes and encodes the specified object as valid XML text.
      Parameters:
      value - The object being serialized.
      preserveWhitespace - If true, then we're serializing XmlFormat.MIXED_PWS or XmlFormat.TEXT_PWS content.
      Returns:
      This object.
    • textUri

      public XmlWriter textUri(Object value)
      Same as text(Object) but treats the value as a URL to resolved then serialized.
      Parameters:
      value - The object being serialized.
      Returns:
      This object.
    • cr

      public XmlWriter cr(int depth)
      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 class SerializerWriter
      Parameters:
      depth - The indentation.
      Returns:
      This object.
    • cre

      public XmlWriter cre(int depth)
      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 class SerializerWriter
      Parameters:
      depth - The indentation.
      Returns:
      This object.
    • appendln

      public XmlWriter appendln(int indent, String text)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text, followed by a newline (if the useWhitespace setting is enabled).
      Overrides:
      appendln in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      text - The text to write.
      Returns:
      This object.
    • appendln

      public XmlWriter appendln(String text)
      Description copied from class: SerializerWriter
      Writes the specified text followed by a newline (if the useWhitespace setting is enabled).
      Overrides:
      appendln in class SerializerWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • append

      public XmlWriter append(int indent, String text)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text.
      Overrides:
      append in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      text - The text to write.
      Returns:
      This object.
    • append

      public XmlWriter append(int indent, char c)
      Description copied from class: SerializerWriter
      Writes an indent (if the useWhitespace setting is enabled), followed by text.
      Overrides:
      append in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      c - The character to write.
      Returns:
      This object.
    • s

      public XmlWriter s()
      Description copied from class: SerializerWriter
      Adds a whitespace character to the output if the useWhitespace setting is enabled.
      Overrides:
      s in class SerializerWriter
      Returns:
      This object.
    • q

      public XmlWriter q()
      Description copied from class: SerializerWriter
      Adds the quote character specified by the quoteChar setting to the output.
      Overrides:
      q in class SerializerWriter
      Returns:
      This object.
    • i

      public XmlWriter i(int indent)
      Description copied from class: SerializerWriter
      Writes an indent to the writer if the useWhitespace setting is enabled.
      Overrides:
      i in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      Returns:
      This object.
    • ie

      public XmlWriter ie(int indent)
      Description copied from class: SerializerWriter
      Writes an end-of-line indent to the writer if the useWhitespace setting is enabled.
      Overrides:
      ie in class SerializerWriter
      Parameters:
      indent - The number of tabs to indent.
      Returns:
      This object.
    • nl

      public XmlWriter nl(int indent)
      Description copied from class: SerializerWriter
      Writes a newline to the writer if the useWhitespace setting is enabled.
      Overrides:
      nl in class SerializerWriter
      Parameters:
      indent - The current indentation level.
      Returns:
      This object.
    • append

      public XmlWriter append(Object text)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if it isn't null.
      Overrides:
      append in class SerializerWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • append

      public XmlWriter append(String text)
      Description copied from class: SerializerWriter
      Writes the specified text to the writer if it isn't null.
      Overrides:
      append in class SerializerWriter
      Parameters:
      text - The text to write.
      Returns:
      This object.
    • append

      public XmlWriter append(char c)
      Specified by:
      append in interface Appendable
      Overrides:
      append in class SerializerWriter
    • w

      public XmlWriter w(char c)
      Description copied from class: SerializerWriter
      Writes the specified character to the writer.
      Overrides:
      w in class SerializerWriter
      Parameters:
      c - The character to write.
      Returns:
      This object.
    • w

      public XmlWriter w(String s)
      Description copied from class: SerializerWriter
      Writes the specified string to the writer.
      Overrides:
      w in class SerializerWriter
      Parameters:
      s - The string to write.
      Returns:
      This object.
    • toString

      public String toString()
      Overrides:
      toString in class Object