Class XmlSave
java.lang.Object
org.libxmq.imp.xml.XmlSave
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 TypeMethodDescriptionstatic voidattr_serialize_text(StringBuilder buf, String s) Port of xmlBufAttrSerializeTxtContent for an utf-8 document.static StringdocDump(XmlDocument doc, String encoding) Dump a document like libxml2 xmlDocDumpMemoryEnc(doc, ..., encoding), ie without formatting.static StringdocDump(XmlDocument doc, String encoding, boolean format) Dump a document like libxml2 xmlDocDumpFormatMemoryEnc(doc, ..., encoding, format).static booleanencodingSupported(String encoding) Is the output encoding supported by transcode (UTF-8, ISO-8859-1, ASCII, UTF-16)?static voidescape_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.static StringnodeDump(XmlDocument doc, XmlNode node, int level, boolean format) Dump a node like libxml2 xmlNodeDump(buf, doc, node, level, format).static voidnodeDumpOutput(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[]The text converted to the encoding, characters the encoding cannot represent become decimal character references (like libxml2 output encoders).static voidwrite_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 "
-
Method Details
-
docDump
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
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
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
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
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
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
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
Port of xmlBufAttrSerializeTxtContent for an utf-8 document.- Parameters:
buf- The output.s- The attribute text to escape.
-