Class XmlDomApi

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

public final class XmlDomApi extends Object
The C dom api (src/main/c/parts/xml_dom.h) on the java dom, with the same semantics, so that C code using it can be ported line by line (eg the xslt engine). The C name xml_node_first_child is nodeFirstChild here, XmlDom is XmlDocument, XMQNode is XmlNode, XMQAttr is XmlAttr (attributes are nodes) and XmlNs is XmlNs.
  • Field Details

    • ELEMENT

      public static final int ELEMENT
      An element.
      See Also:
    • ATTRIBUTE

      public static final int ATTRIBUTE
      An attribute.
      See Also:
    • TEXT

      public static final int TEXT
      A text node.
      See Also:
    • CDATA

      public static final int CDATA
      A CDATA section.
      See Also:
    • ENTITY_REF

      public static final int ENTITY_REF
      An entity reference.
      See Also:
    • PI

      public static final int PI
      A processing instruction.
      See Also:
    • COMMENT

      public static final int COMMENT
      A comment.
      See Also:
    • DOCUMENT

      public static final int DOCUMENT
      The document.
      See Also:
    • DTD

      public static final int DTD
      A document type declaration.
      See Also:
    • ELEMENT_DECL

      public static final int ELEMENT_DECL
      An element declaration in a DTD.
      See Also:
    • ATTRIBUTE_DECL

      public static final int ATTRIBUTE_DECL
      An attribute declaration in a DTD.
      See Also:
    • ENTITY_DECL

      public static final int ENTITY_DECL
      An entity declaration in a DTD.
      See Also:
    • NAMESPACE

      public static final int NAMESPACE
      A namespace declaration.
      See Also:
    • NOTATION_DECL

      public static final int NOTATION_DECL
      A notation declaration in a DTD.
      See Also:
    • PE_REF

      public static final int PE_REF
      A parameter entity reference in a DTD.
      See Also:
    • XML_NAMESPACE

      public static final String XML_NAMESPACE
      The xml namespace uri.
      See Also:
    • NS_NONE

      public static final int NS_NONE
      The namespace actions of the C XMQNSAction: no namespace.
      See Also:
    • NS_PARENT

      public static final int NS_PARENT
      Use the namespace of the parent.
      See Also:
    • NS_HERE

      public static final int NS_HERE
      Declare the namespace on the element itself.
      See Also:
    • NS_ANCESTOR

      public static final int NS_ANCESTOR
      Use a namespace declared on an ancestor, declare it on the top element if not found.
      See Also:
  • Method Details

    • domNew

      public static XmlDocument domNew()
      A new empty document (xml_dom_new).
      Returns:
      The document.
    • domDocument

      public static XmlNode domDocument(XmlDocument dom)
      The document node of a dom, the same object in java.
      Parameters:
      dom - The dom.
      Returns:
      The document node.
    • domRootElement

      public static XmlNode domRootElement(XmlDocument dom)
      The root element.
      Parameters:
      dom - The dom.
      Returns:
      The root element or null.
    • domSetRootElement

      public static void domSetRootElement(XmlDocument dom, XmlNode root)
      Replace the root element (or add it).
      Parameters:
      dom - The dom.
      root - The new root element.
    • domVersion

      public static String domVersion(XmlDocument dom)
      The version of the xml declaration.
      Parameters:
      dom - The dom.
      Returns:
      The version or null.
    • domSetVersion

      public static void domSetVersion(XmlDocument dom, String v)
      Set the version.
      Parameters:
      dom - The dom.
      v - The version.
    • domEncoding

      public static String domEncoding(XmlDocument dom)
      The encoding of the xml declaration.
      Parameters:
      dom - The dom.
      Returns:
      The encoding or null.
    • domSetEncoding

      public static void domSetEncoding(XmlDocument dom, String e)
      Set the encoding.
      Parameters:
      dom - The dom.
      e - The encoding.
    • domUrl

      public static String domUrl(XmlDocument dom)
      Where the document was loaded from (libxml2 doc->URL).
      Parameters:
      dom - The dom.
      Returns:
      The url or null.
    • domSetUrl

      public static void domSetUrl(XmlDocument dom, String url)
      Set the url.
      Parameters:
      dom - The dom.
      url - The url.
    • domStandalone

      public static int domStandalone(XmlDocument dom)
      The standalone flag: -1 not given, 0 no, 1 yes.
      Parameters:
      dom - The dom.
      Returns:
      The flag.
    • domSetStandalone

      public static void domSetStandalone(XmlDocument dom, int s)
      Set the standalone flag.
      Parameters:
      dom - The dom.
      s - The flag.
    • domDtd

      public static XmlNode domDtd(XmlDocument dom)
      The internal subset.
      Parameters:
      dom - The dom.
      Returns:
      The dtd or null.
    • domSetDtd

      public static XmlNode domSetDtd(XmlDocument dom, String name, String public_id, String system_id)
      Replace the dtd with a new one without declarations, before the root element (xml_dom_set_dtd).
      Parameters:
      dom - The dom.
      name - The name.
      public_id - The public id or null.
      system_id - The system id or null.
      Returns:
      The dtd.
    • dtdPublicId

      public static String dtdPublicId(XmlNode dtd)
      The public id of a dtd.
      Parameters:
      dtd - The dtd.
      Returns:
      The public id or null.
    • dtdSystemId

      public static String dtdSystemId(XmlNode dtd)
      The system id of a dtd.
      Parameters:
      dtd - The dtd.
      Returns:
      The system id or null.
    • domGetEntity

      public static XmlNode domGetEntity(XmlDocument dom, String name)
      A general entity declared in the internal subset.
      Parameters:
      dom - The dom.
      name - The name.
      Returns:
      The declaration or null.
    • entityDeclSystemId

      public static String entityDeclSystemId(XmlNode decl)
      The system id of an entity declaration.
      Parameters:
      decl - The declaration.
      Returns:
      The system id or null.
    • nodeNewElement

      public static XmlNode nodeNewElement(XmlDocument dom, String name, XmlNs ns)
      A new element (xml_node_new_element).
      Parameters:
      dom - The dom.
      name - The local name.
      ns - The namespace or null.
      Returns:
      The element.
    • nodeNewText

      public static XmlNode nodeNewText(XmlDocument dom, String text)
      A new text node.
      Parameters:
      dom - The dom.
      text - The text, null is "".
      Returns:
      The node.
    • nodeNewCdata

      public static XmlNode nodeNewCdata(XmlDocument dom, String text)
      A new cdata section.
      Parameters:
      dom - The dom.
      text - The content.
      Returns:
      The node.
    • nodeNewComment

      public static XmlNode nodeNewComment(XmlDocument dom, String text)
      A new comment.
      Parameters:
      dom - The dom.
      text - The content.
      Returns:
      The node.
    • nodeNewPi

      public static XmlNode nodeNewPi(XmlDocument dom, String target, String data)
      A new processing instruction.
      Parameters:
      dom - The dom.
      target - The target.
      data - The data or null.
      Returns:
      The node.
    • nodeNewEntityRef

      public static XmlNode nodeNewEntityRef(XmlDocument dom, String name)
      A new entity reference.
      Parameters:
      dom - The dom.
      name - The entity name.
      Returns:
      The node.
    • nodeNewNamespaceNode

      public static XmlNode nodeNewNamespaceNode(XmlNode element, String prefix, String href, int index)
      An xpath namespace node of element, not linked into the element.
      Parameters:
      element - The element.
      prefix - The prefix or null.
      href - The uri.
      index - The position on the namespace axis (stored as its line in C).
      Returns:
      The node.
    • nodeFree

      public static void nodeFree(XmlNode n)
      Unlink a node (the garbage collector frees it).
      Parameters:
      n - The node.
    • nodeKind

      public static int nodeKind(XmlNode n)
      The kind of a node, the C XmlNodeKind values.
      Parameters:
      n - The node.
      Returns:
      The kind.
    • nodeDom

      public static XmlDocument nodeDom(XmlNode n)
      The dom of a node.
      Parameters:
      n - The node.
      Returns:
      The document.
    • nodeParent

      public static XmlNode nodeParent(XmlNode n)
      The parent (the owner element of an attribute or namespace node).
      Parameters:
      n - The node.
      Returns:
      The parent or null.
    • nodeFirstChild

      public static XmlNode nodeFirstChild(XmlNode n)
      The first child.
      Parameters:
      n - The node.
      Returns:
      The child or null.
    • nodeLastChild

      public static XmlNode nodeLastChild(XmlNode n)
      The last child.
      Parameters:
      n - The node.
      Returns:
      The child or null.
    • nodeNext

      public static XmlNode nodeNext(XmlNode n)
      The next sibling (for an attribute the next attribute).
      Parameters:
      n - The node.
      Returns:
      The sibling or null.
    • nodePrev

      public static XmlNode nodePrev(XmlNode n)
      The previous sibling (for an attribute the previous attribute).
      Parameters:
      n - The node.
      Returns:
      The sibling or null.
    • nodeName

      public static String nodeName(XmlNode n)
      The name: local name of elements and attributes, the target of a pi, the entity name of a reference, the prefix of a namespace node, null for text ("textnoenc" for text written without escaping), comments and documents.
      Parameters:
      n - The node.
      Returns:
      The name or null.
    • nodeSetName

      public static void nodeSetName(XmlNode n, String name)
      Set the name.
      Parameters:
      n - The node.
      name - The name.
    • nodeContent

      public static String nodeContent(XmlNode n)
      The content of text, cdata, comments, pis (the data) and namespace nodes (the uri), null for other nodes.
      Parameters:
      n - The node.
      Returns:
      The content or null.
    • nodeSetContent

      public static void nodeSetContent(XmlNode n, String content)
      Set the content, for elements and attributes the children are replaced with one text node (none for "").
      Parameters:
      n - The node.
      content - The content.
    • nodeAppendContent

      public static void nodeAppendContent(XmlNode n, String content)
      Append to the content of a text like node.
      Parameters:
      n - The node.
      content - The text to append.
    • nodeStringValue

      public static String nodeStringValue(XmlNode n)
      The string value: text content of elements, attributes and documents, the character of a character reference (other entity references contribute nothing).
      Parameters:
      n - The node.
      Returns:
      The string value, never null.
    • nodeNs

      public static XmlNs nodeNs(XmlNode n)
      The namespace of an element or attribute.
      Parameters:
      n - The node.
      Returns:
      The namespace or null.
    • nodeNsUri

      public static String nodeNsUri(XmlNode n)
      The namespace uri of the node, null if none (or "").
      Parameters:
      n - The node.
      Returns:
      The uri or null.
    • nodeNsPrefix

      public static String nodeNsPrefix(XmlNode n)
      The prefix of the namespace of the node.
      Parameters:
      n - The node.
      Returns:
      The prefix or null.
    • nodeSetNs

      public static void nodeSetNs(XmlNode n, XmlNs ns)
      Set the namespace of an element or attribute.
      Parameters:
      n - The node.
      ns - The namespace.
    • nodeLine

      public static int nodeLine(XmlNode n)
      The source line.
      Parameters:
      n - The node.
      Returns:
      The line.
    • nodeSetLine

      public static void nodeSetLine(XmlNode n, int line)
      Set the source line.
      Parameters:
      n - The node.
      line - The line.
    • nodeUserData

      public static Object nodeUserData(XmlNode n)
      The user data.
      Parameters:
      n - The node.
      Returns:
      The data or null.
    • nodeSetUserData

      public static void nodeSetUserData(XmlNode n, Object data)
      Set the user data.
      Parameters:
      n - The node.
      data - The data.
    • nodeAppendChild

      public static XmlNode nodeAppendChild(XmlNode parent, XmlNode child)
      Append a child without merging text (xml_node_append_child), the child is unlinked first.
      Parameters:
      parent - The parent.
      child - The child.
      Returns:
      The child.
    • nodeAddChild

      public static XmlNode nodeAddChild(XmlNode parent, XmlNode child)
      Append a child, text is merged into a last text child (xml_node_add_child), then the child is dropped and the last child returned.
      Parameters:
      parent - The parent.
      child - The child.
      Returns:
      The node holding the child.
    • nodeAddPrevSibling

      public static XmlNode nodeAddPrevSibling(XmlNode node, XmlNode n)
      Insert n before node.
      Parameters:
      node - The node.
      n - The new sibling.
      Returns:
      n.
    • nodeAddNextSibling

      public static XmlNode nodeAddNextSibling(XmlNode node, XmlNode n)
      Insert n after node.
      Parameters:
      node - The node.
      n - The new sibling.
      Returns:
      n.
    • nodeUnlink

      public static void nodeUnlink(XmlNode n)
      Unlink a node from its parent (an attribute from its element).
      Parameters:
      n - The node.
    • nodeReplace

      public static XmlNode nodeReplace(XmlNode node, XmlNode n)
      Replace node with n.
      Parameters:
      node - The node.
      n - The replacement.
      Returns:
      node.
    • nodeNumChildren

      public static int nodeNumChildren(XmlNode n)
      The number of children.
      Parameters:
      n - The node.
      Returns:
      The count.
    • nodeCopy

      public static XmlNode nodeCopy(XmlDocument dom, XmlNode node, boolean deep)
      Copy a node (not a document) into dom, deep with the children, the namespaces used are the copies of the declarations copied with it or the original ones (xml_node_copy).
      Parameters:
      dom - The dom of the copy.
      node - The node.
      deep - Copy the children too.
      Returns:
      The copy.
    • nodeCompareOrder

      public static int nodeCompareOrder(XmlNode a, XmlNode b)
      Compare two nodes in document order (xml_node_compare_order): -1, 0 or 1. Nodes of different trees are ordered by the creation of their roots.
      Parameters:
      a - A node.
      b - Another node.
      Returns:
      The order.
    • nodeAttrs

      public static List<XmlAttr> nodeAttrs(XmlNode e)
      The attributes of an element (the live list, copy it to change attributes while iterating).
      Parameters:
      e - The element.
      Returns:
      The attributes.
    • nodeFirstAttr

      public static XmlAttr nodeFirstAttr(XmlNode e)
      The first attribute.
      Parameters:
      e - The element.
      Returns:
      The attribute or null.
    • attrNext

      public static XmlAttr attrNext(XmlAttr a)
      The next attribute.
      Parameters:
      a - The attribute.
      Returns:
      The next or null.
    • attrName

      public static String attrName(XmlAttr a)
      The name of an attribute.
      Parameters:
      a - The attribute.
      Returns:
      The local name.
    • attrOwner

      public static XmlNode attrOwner(XmlAttr a)
      The element of an attribute.
      Parameters:
      a - The attribute.
      Returns:
      The element or null.
    • attrNode

      public static XmlNode attrNode(XmlAttr a)
      The attribute as a node, the same object in java.
      Parameters:
      a - The attribute.
      Returns:
      The node.
    • nodeAsAttr

      public static XmlAttr nodeAsAttr(XmlNode n)
      The node as an attribute.
      Parameters:
      n - The node.
      Returns:
      The attribute or null.
    • nodeGetAttr

      public static XmlAttr nodeGetAttr(XmlNode e, String name, String ns_uri)
      The attribute with this name and namespace uri (null or "" for none).
      Parameters:
      e - The element.
      name - The local name.
      ns_uri - The uri.
      Returns:
      The attribute or null.
    • nodeAppendAttr

      public static XmlAttr nodeAppendAttr(XmlNode e, String name, XmlNs ns, String value)
      Append an attribute (without checking for an existing one).
      Parameters:
      e - The element.
      name - The local name.
      ns - The namespace or null.
      value - The value, null or "" for no text child.
      Returns:
      The attribute.
    • nodeSetAttr

      public static XmlAttr nodeSetAttr(XmlNode e, String name, XmlNs ns, String value)
      Set an attribute, replacing the value (and namespace) of an existing one.
      Parameters:
      e - The element.
      name - The local name.
      ns - The namespace or null.
      value - The value.
      Returns:
      The attribute.
    • nodeMoveAttr

      public static XmlAttr nodeMoveAttr(XmlNode e, XmlAttr a)
      Move an attribute to element, an attribute with the same name and namespace is replaced (xml_node_move_attr).
      Parameters:
      e - The element.
      a - The attribute.
      Returns:
      The attribute.
    • nodeRemoveAttr

      public static boolean nodeRemoveAttr(XmlNode e, String name, String ns_uri)
      Remove the attribute with this name and namespace uri.
      Parameters:
      e - The element.
      name - The local name.
      ns_uri - The uri or null.
      Returns:
      True if one was removed.
    • nsPrefix

      public static String nsPrefix(XmlNs ns)
      The prefix of a namespace.
      Parameters:
      ns - The namespace.
      Returns:
      The prefix or null.
    • nsHref

      public static String nsHref(XmlNs ns)
      The uri of a namespace, "" for an undeclaration, null for a prefix declared without uri.
      Parameters:
      ns - The namespace.
      Returns:
      The uri.
    • nsSetHref

      public static void nsSetHref(XmlNs ns, String href)
      Set the uri.
      Parameters:
      ns - The namespace.
      href - The uri.
    • nodeNsDecls

      public static List<XmlNs> nodeNsDecls(XmlNode e)
      The namespace declarations of an element (the live list, copy it to change it while iterating).
      Parameters:
      e - The element.
      Returns:
      The declarations.
    • nsDeclare

      public static XmlNs nsDeclare(XmlNode e, String prefix, String href)
      Declare a namespace on element, null if the prefix is already declared there (xml_ns_declare).
      Parameters:
      e - The element.
      prefix - The prefix or null.
      href - The uri.
      Returns:
      The declaration or null.
    • nsMoveDeclTo

      public static void nsMoveDeclTo(XmlNode from, XmlNs ns, XmlNode to)
      Move the declaration ns from element from to the front of the declarations of to.
      Parameters:
      from - The element declaring ns.
      ns - The declaration.
      to - The new element.
    • nsMoveDeclLast

      public static void nsMoveDeclLast(XmlNode e, XmlNs ns)
      Move the declaration ns last among the declarations of element.
      Parameters:
      e - The element.
      ns - The declaration.
    • nsRemoveDecl

      public static void nsRemoveDecl(XmlNode e, XmlNs ns, XmlNs replacement)
      Remove the declaration ns from element, the nodes of the subtree using it use replacement instead (xml_ns_remove_decl).
      Parameters:
      e - The element.
      ns - The declaration.
      replacement - The namespace to use instead, or null.
    • nsLookupPrefix

      public static XmlNs nsLookupPrefix(XmlNode node, String prefix)
      Find the declaration of prefix in scope of node (xmlSearchNs), the xml prefix is always declared.
      Parameters:
      node - The node.
      prefix - The prefix, null for the default namespace.
      Returns:
      The declaration or null.
    • nsLookupHref

      public static XmlNs nsLookupHref(XmlNode node, String href)
      Find a declaration of href in scope of node whose prefix is not shadowed (xmlSearchNsByHref).
      Parameters:
      node - The node.
      href - The uri.
      Returns:
      The declaration or null.
    • nsSplitPuri

      public static String[] nsSplitPuri(String puri)
      Split a namespace written as {prefix}uri into the prefix and the uri (xml_ns_split_puri).
      Parameters:
      puri - The uri, optionally with a {prefix} first.
      Returns:
      The prefix (null if none) and the uri, or null if the } is missing.
    • nodeApplyXmqns

      public static boolean nodeApplyXmqns(XmlNode element, int action, String puri)
      Set the namespace of an element added to the dom, as the C xmqAddElement does with an XMQNS (xml_node_apply_xmqns).
      Parameters:
      element - The element, already added to its parent.
      action - NS_NONE, NS_PARENT, NS_HERE or NS_ANCESTOR.
      puri - The uri for NS_HERE and NS_ANCESTOR, optionally with a {prefix} first.
      Returns:
      True if ok, false if the uri is malformed or the prefix is already declared on the element for another uri.
    • nodeReconcileNs

      public static void nodeReconcileNs(XmlNode node)
      Make every namespace used in the subtree of node declared in scope (xml_node_reconcile_ns).
      Parameters:
      node - The element.