Class XmlSave

java.lang.Object
org.libxmq.imp.xml.XmlSave

public final class XmlSave extends Object
Serializes the xmq DOM as xml. This is a port of the libxml2 (Copyright (C) 1998-2012 Daniel Veillard, MIT license) xmlsave.c serializer, so that the output is identical to the C version of xmq, which calls xmlDocDumpMemoryEnc and xmlNodeDump.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Port of xmlBufAttrSerializeTxtContent for an utf-8 document.
    static String
    docDump(XmlDocument doc, String encoding)
    Dump a document like libxml2 xmlDocDumpMemoryEnc(doc, ..., encoding), ie without formatting.
    static String
    docDump(XmlDocument doc, String encoding, boolean format)
    Dump a document like libxml2 xmlDocDumpFormatMemoryEnc(doc, ..., encoding, format).
    static boolean
    Is the output encoding supported by transcode (UTF-8, ISO-8859-1, ASCII, UTF-16)?
    static void
    Port of xmlEscapeContent, used for text when the output encoding is utf-8, with the control characters of libxml2 2.16 xmlSerializeText.
    static String
    nodeDump(XmlDocument doc, XmlNode node, int level, boolean format)
    Dump a node like libxml2 xmlNodeDump(buf, doc, node, level, format).
    static void
    nodeDumpOutput(StringBuilder out, XmlDocument doc, XmlNode node, int level, boolean format, String encoding)
    Serialize a node like libxml2 xmlNodeDumpOutput: in the XHTML mode if the dtd of doc is an XHTML 1.0 dtd.
    static byte[]
    transcode(String text, String encoding)
    The text converted to the encoding, characters the encoding cannot represent become decimal character references (like libxml2 output encoders).
    static void
    Port of xmlBufWriteQuotedString: quote with double quotes, unless the string contains double quotes, then use single quotes, unless it contains both, then use double quotes and escape them as "

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • docDump

      public static String docDump(XmlDocument doc, String encoding)
      Dump a document like libxml2 xmlDocDumpMemoryEnc(doc, ..., encoding), ie without formatting. An html document is dumped as html.
      Parameters:
      doc - The document.
      encoding - The encoding to put in the xml declaration, eg utf-8.
      Returns:
      The serialized document.
    • docDump

      public static String docDump(XmlDocument doc, String encoding, boolean format)
      Dump a document like libxml2 xmlDocDumpFormatMemoryEnc(doc, ..., encoding, format). Like the C version, which has one dom for xml and html, an html document is dumped as xml too, use HtmlSave.docContentDump for html.
      Parameters:
      doc - The document.
      encoding - The encoding to put in the xml declaration, eg utf-8.
      format - True to indent the output.
      Returns:
      The serialized document.
    • nodeDump

      public static String nodeDump(XmlDocument doc, XmlNode node, int level, boolean format)
      Dump a node like libxml2 xmlNodeDump(buf, doc, node, level, format).
      Parameters:
      doc - The document, can be null.
      node - The node to dump, its children are dumped too.
      level - The initial indentation level.
      format - True to add formatting whitespace.
      Returns:
      The serialized node.
    • nodeDumpOutput

      public static void nodeDumpOutput(StringBuilder out, XmlDocument doc, XmlNode node, int level, boolean format, String encoding)
      Serialize a node like libxml2 xmlNodeDumpOutput: in the XHTML mode if the dtd of doc is an XHTML 1.0 dtd. Text is written as a String (transcode afterwards for other encodings); encoding (null is UTF-8) is only used for the XHTML meta tag.
      Parameters:
      out - Where to append the output.
      doc - The document whose dtd decides the XHTML mode, can be null.
      node - The node.
      level - The indentation level.
      format - True to indent.
      encoding - The encoding for the meta tag, or null.
    • encodingSupported

      public static boolean encodingSupported(String encoding)
      Is the output encoding supported by transcode (UTF-8, ISO-8859-1, ASCII, UTF-16)?
      Parameters:
      encoding - The encoding name, null is UTF-8.
      Returns:
      True if supported.
    • transcode

      public static byte[] transcode(String text, String encoding)
      The text converted to the encoding, characters the encoding cannot represent become decimal character references (like libxml2 output encoders).
      Parameters:
      text - The text.
      encoding - The encoding, null is UTF-8.
      Returns:
      The bytes, or null if the encoding is not supported.
    • write_quoted

      public static void write_quoted(StringBuilder buf, String s)
      Port of xmlBufWriteQuotedString: quote with double quotes, unless the string contains double quotes, then use single quotes, unless it contains both, then use double quotes and escape them as "
      Parameters:
      buf - The output.
      s - The string to quote.
    • escape_content

      public static void escape_content(StringBuilder buf, String s)
      Port of xmlEscapeContent, used for text when the output encoding is utf-8, with the control characters of libxml2 2.16 xmlSerializeText.
      Parameters:
      buf - The output.
      s - The text to escape.
    • attr_serialize_text

      public static void attr_serialize_text(StringBuilder buf, String s)
      Port of xmlBufAttrSerializeTxtContent for an utf-8 document.
      Parameters:
      buf - The output.
      s - The attribute text to escape.