Class XPathContext

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class XPathContext
    extends java.lang.Object
    implements java.lang.Cloneable
    Helper class that keeps track of the XPath of matched nodes during comparison.
    • Constructor Summary

      Constructors 
      Constructor Description
      XPathContext()
      Starts with an empty context.
      XPathContext​(java.util.Map<java.lang.String,​java.lang.String> prefix2uri)
      Starts with an empty context and a given namespace mapping.
      XPathContext​(java.util.Map<java.lang.String,​java.lang.String> prefix2uri, org.w3c.dom.Node root)
      Starts with the context of an optional root node and an optional namespace mapping.
      XPathContext​(org.w3c.dom.Node root)
      Starts with the context of a root node.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAttribute​(javax.xml.namespace.QName attribute)
      Adds knowledge about a single attribute of the current node.
      void addAttributes​(java.lang.Iterable<? extends javax.xml.namespace.QName> attributes)
      Adds knowledge about the current node's attributes.
      void appendChildren​(java.lang.Iterable<? extends XPathContext.NodeInfo> children)
      Adds knowledge about the current node's children appending to the knowledge already present.
      XPathContext clone()
      Creates a deep copy of this XPathContext.
      java.lang.String getParentXPath()
      Stringifies the XPath of the current node's parent.
      java.lang.String getXPath()
      Stringifies the XPath of the current node.
      void navigateToAttribute​(javax.xml.namespace.QName attribute)
      Moves from the current node to the given attribute.
      void navigateToChild​(int index)
      Moves from the current node to the given child node.
      void navigateToParent()
      Moves back to the parent.
      void setChildren​(java.lang.Iterable<? extends XPathContext.NodeInfo> children)
      Adds knowledge about the current node's children replacing existing knowledge.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XPathContext

        public XPathContext()
        Starts with an empty context.
      • XPathContext

        public XPathContext​(org.w3c.dom.Node root)
        Starts with the context of a root node.
        Parameters:
        root - the root node
      • XPathContext

        public XPathContext​(java.util.Map<java.lang.String,​java.lang.String> prefix2uri)
        Starts with an empty context and a given namespace mapping.
        Parameters:
        prefix2uri - maps from prefix to namespace URI.
      • XPathContext

        public XPathContext​(java.util.Map<java.lang.String,​java.lang.String> prefix2uri,
                            org.w3c.dom.Node root)
        Starts with the context of an optional root node and an optional namespace mapping.
        Parameters:
        prefix2uri - maps from prefix to namespace URI.
        root - optional root node that determines the initial XPath
    • Method Detail

      • navigateToChild

        public void navigateToChild​(int index)
        Moves from the current node to the given child node.
        Parameters:
        index - index of child to navigate to
      • navigateToAttribute

        public void navigateToAttribute​(javax.xml.namespace.QName attribute)
        Moves from the current node to the given attribute.
        Parameters:
        attribute - name of attribute to navigate to
      • navigateToParent

        public void navigateToParent()
        Moves back to the parent.
      • addAttributes

        public void addAttributes​(java.lang.Iterable<? extends javax.xml.namespace.QName> attributes)
        Adds knowledge about the current node's attributes.
        Parameters:
        attributes - attributes to add
      • addAttribute

        public void addAttribute​(javax.xml.namespace.QName attribute)
        Adds knowledge about a single attribute of the current node.
        Parameters:
        attribute - attribute to add
      • setChildren

        public void setChildren​(java.lang.Iterable<? extends XPathContext.NodeInfo> children)
        Adds knowledge about the current node's children replacing existing knowledge.
        Parameters:
        children - children to add
      • appendChildren

        public void appendChildren​(java.lang.Iterable<? extends XPathContext.NodeInfo> children)
        Adds knowledge about the current node's children appending to the knowledge already present.
        Parameters:
        children - children to add
      • getXPath

        public java.lang.String getXPath()
        Stringifies the XPath of the current node.
        Returns:
        current XPath
      • getParentXPath

        public java.lang.String getParentXPath()
        Stringifies the XPath of the current node's parent.
        Returns:
        parent's XPath
      • clone

        public XPathContext clone()
        Creates a deep copy of this XPathContext.
        Overrides:
        clone in class java.lang.Object