Class HtmlSave

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

public final class HtmlSave extends Object
Serialize an html document or node exactly like the libxml2 (2.16) html serializer htmlNodeDumpInternal does, the same as the C version (src/main/c/parts/xml_html_save.c): text is escaped with & < > only (non ascii is written as it is), attributes are always quoted with ". The code is ported from libxml2 HTMLtree.c, HTMLparser.c (the element table), xmlsave.c (xmlSerializeText) and buf.c (xmlBufWriteQuotedString) (Copyright (C) 1998-2012 Daniel Veillard, MIT license).
  • Method Details

    • docContentDump

      public static String docContentDump(XmlDocument doc, boolean format)
      Dump a whole html document, like libxml2 htmlDocContentDumpFormatOutput. The C version of xmq calls htmlDocContentDumpOutput(out, doc, "utf8") which is the same as using format=true.
      Parameters:
      doc - The document.
      format - If true, then add newlines around block elements.
      Returns:
      The serialized document.
    • nodeDump

      public static String nodeDump(XmlDocument doc, XmlNode node, boolean format)
      Dump a node and its children, like libxml2 htmlNodeDumpFormatOutput. Note that libxml2 htmlNodeDump always uses format=1.
      Parameters:
      doc - The document, used to decide if the escaping should be html or xml style.
      node - The node to dump.
      format - If true, then add newlines around block elements.
      Returns:
      The serialized node.
    • nodeDumpFormatOutput

      public static void nodeDumpFormatOutput(StringBuilder out, XmlDocument doc, XmlNode cur, boolean format)
      Dump a node and its children into a string builder, port of htmlNodeDumpInternal (libxml2 2.16, encoding NULL so no meta charset handling), like xml_html_node in C.
      Parameters:
      out - The output.
      doc - The document (not used, kept for the callers).
      cur - The node to dump.
      format - If true, then add newlines around block elements.
    • setMetaEncoding

      public static int setMetaEncoding(XmlDocument doc, String encoding)
      Create or update the meta tags with the encoding in the head (libxml2 htmlSetMetaEncoding).
      Parameters:
      doc - The document.
      encoding - The encoding.
      Returns:
      0, or 1 if there is no html/head.