Class HtmlParser
java.lang.Object
org.libxmq.imp.xml.HtmlParser
An html parser that builds the same tree as libxml2 (2.16) htmlReadMemory does with
the options libxmq uses (HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET,
optionally HTML_PARSE_NOBLANKS, encoding UTF-8): html5 tokenization, libxml2's tree
construction with implied html/head/body elements and implicit closing of elements,
a default html 4.0 transitional doctype if none is given. A port of the C version
src/main/c/parts/xml_html_parser.c.
Element names are lowercased, there are no namespaces. Character references and html
named character references (like ) are decoded. Raw text (script, style...)
is stored as cdata nodes, like libxml2. Like libxml2 the parser works on the UTF-8
bytes of the input, which gives the same chunking of text, which affects the blank
detection. Errors are never reported (like xmq which parses without a message
callback), the parser always recovers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisBooleanAttr(String name) Check if an attribute is an html boolean attribute, like libxml2 htmlIsBooleanAttr.static XmlDocumentparse(byte[] content, boolean noblanks) Parse html content (UTF-8 bytes, invalid sequences become U+FFFD) into a document.static XmlDocumentParse html content into a document, like libxml2 htmlReadMemory with the options HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET.
-
Method Details
-
parse
Parse html content into a document, like libxml2 htmlReadMemory with the options HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET.- Parameters:
content- The html source.noblanks- If true then also HTML_PARSE_NOBLANKS is used, ie ignorable whitespace text nodes are dropped.- Returns:
- The html document, without a root element if there was no content.
-
parse
Parse html content (UTF-8 bytes, invalid sequences become U+FFFD) into a document.- Parameters:
content- The html source.noblanks- If true then ignorable whitespace text nodes are dropped.- Returns:
- The html document, without a root element if there was no content.
-
isBooleanAttr
Check if an attribute is an html boolean attribute, like libxml2 htmlIsBooleanAttr.- Parameters:
name- The attribute name.- Returns:
- True if the attribute is boolean (checked, selected...).
-