Class XmlEntityExpander

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

public final class XmlEntityExpander extends Object
Explicit entity expansion, like xml_expand_entities in the C version (parts/xml_parser.c). Entities are never expanded when parsing: a reference to a declared entity stays as an XmlEntityRef. This replaces every reference to a declared internal general entity, also inside attribute values, with its replacement text parsed as content at the position of the reference (so the namespaces in scope there are used). References inside the replacement text are expanded too. Character references, undeclared entities and external entities (never loaded) are kept. Adjacent text nodes are merged. The limits of libxml2 are enforced: loops, 19 nested entities (20 inputs counting the document) and the amplification factor 5 once more than 1MB (UTF-8 bytes) has been expanded. On an error the references expanded so far stay expanded, the one being expanded is kept.
  • Method Details

    • expand

      public static void expand(XmlDocument doc, String only, long input_size, int options) throws XmlParseException
      Expand the entities of a document.
      Parameters:
      doc - The document.
      only - Expand only references to this entity (and everything inside it), or null for all.
      input_size - The size of the parsed source, for the amplification limit.
      options - XmlParser options used when parsing the replacement text, eg NOCDATA.
      Throws:
      XmlParseException - If an entity cannot be expanded, the error field has the message.
    • expand

      public static void expand(XmlDocument doc, String only, long input_size, int options, String source) throws XmlParseException
      Expand the entities of a document, the messages name the source.
      Parameters:
      doc - The document.
      only - Expand only references to this entity (and everything inside it), or null for all.
      input_size - The size of the parsed source, for the amplification limit.
      options - XmlParser options used when parsing the replacement text, eg NOCDATA.
      source - The source name of the messages, eg the file that the document was read from.
      Throws:
      XmlParseException - If an entity cannot be expanded, the error field has the message.