Class XmlParser

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

public final class XmlParser extends Object
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
    Modifier and Type
    Field
    Description
    static final int
    Add the attributes defaulted in the dtd, like XML_PARSE_DTDATTR.
    static final int
    Remove ignorable blank text nodes, like XML_PARSE_NOBLANKS.
    static final int
    Merge cdata sections into text nodes, like XML_PARSE_NOCDATA.
  • Method Summary

    Modifier and Type
    Method
    Description
    parse(byte[] content, String source, int options)
    Parse xml bytes into a document, the bytes are UTF-8, UTF-16 (bom or "<?"
    parse(byte[] content, String source, int options, Consumer<String> messages)
    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.
    parse(String content, String source, int options)
    Parse xml into a document.

    Methods inherited from class Object

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

    • NOBLANKS

      public static final int NOBLANKS
      Remove ignorable blank text nodes, like XML_PARSE_NOBLANKS.
      See Also:
    • NOCDATA

      public static final int NOCDATA
      Merge cdata sections into text nodes, like XML_PARSE_NOCDATA.
      See Also:
    • DTDATTR

      public static final int DTDATTR
      Add 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.