Class XmlParser
java.lang.Object
org.libxmq.imp.xml.XmlParser
An xml parser that builds the xmq DOM. It behaves like the libxml2
(Copyright (C) 1998-2012 Daniel Veillard, MIT license) parser called
by the C version of xmq: xmlReadMemory with XML_PARSE_NOCDATA |
XML_PARSE_NONET and optionally XML_PARSE_NOBLANKS.
Most importantly, entity references are never expanded. A reference to a
declared entity becomes an XmlEntityRef node, both in content and in
attribute values. Character references and the predefined entities
(amp, lt, gt, quot, apos) are expanded into the surrounding text.
The internal subset of the doctype is parsed into declaration nodes,
so that it can be printed back exactly like libxml2 does.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic XmlDocumentParse xml bytes into a document, the bytes are UTF-8, UTF-16 (bom or "<?"static XmlDocumentParse xml bytes into a document, the warnings and recoverable errors (eg namespace errors) go to messages instead of stderr, like the message callback of the C parser.static XmlDocumentParse xml into a document.
-
Field Details
-
NOBLANKS
public static final int NOBLANKSRemove ignorable blank text nodes, like XML_PARSE_NOBLANKS.- See Also:
-
NOCDATA
public static final int NOCDATAMerge cdata sections into text nodes, like XML_PARSE_NOCDATA.- See Also:
-
DTDATTR
public static final int DTDATTRAdd the attributes defaulted in the dtd, like XML_PARSE_DTDATTR.- See Also:
-
-
Method Details
-
parse
public static XmlDocument parse(String content, String source, int options) throws XmlParseException Parse xml into a document.- Parameters:
content- The xml source.source- The source name used in error messages, eg the file name.options- NOBLANKS and/or NOCDATA.- Returns:
- The document.
- Throws:
XmlParseException- If the xml is not well formed.
-
parse
public static XmlDocument parse(byte[] content, String source, int options) throws XmlParseException Parse xml bytes into a document, the bytes are UTF-8, UTF-16 (bom or "<?" pattern) or ISO-8859-1 (declared), like the C version.- Parameters:
content- The xml source.source- The source name used in error messages, eg the file name.options- NOBLANKS and/or NOCDATA.- Returns:
- The document.
- Throws:
XmlParseException- If the xml is not well formed.
-
parse
public static XmlDocument parse(byte[] content, String source, int options, Consumer<String> messages) throws XmlParseException Parse xml bytes into a document, the warnings and recoverable errors (eg namespace errors) go to messages instead of stderr, like the message callback of the C parser.- Parameters:
content- The xml source.source- The source name used in error messages, eg the file name.options- NOBLANKS, NOCDATA and/or DTDATTR.messages- Receives the formatted messages, null for stderr.- Returns:
- The document.
- Throws:
XmlParseException- If the xml is not well formed.
-