Class JAXPXPathEngine

java.lang.Object
org.xmlunit.xpath.JAXPXPathEngine
All Implemented Interfaces:
XPathEngine

public class JAXPXPathEngine extends Object implements XPathEngine
Simplified access to JAXP's XPath API.
  • Constructor Details

    • JAXPXPathEngine

      public JAXPXPathEngine(XPathFactory fac)
      Create an XPathEngine that uses a custom XPathFactory.
      Parameters:
      fac - the factory to use
    • JAXPXPathEngine

      public JAXPXPathEngine()
      Create an XPathEngine that uses JAXP's default XPathFactory under the covers.
  • Method Details

    • selectNodes

      public Iterable<Node> selectNodes(String xPath, Source s)
      Returns a potentially empty collection of Nodes matching an XPath expression.
      Specified by:
      selectNodes in interface XPathEngine
      Parameters:
      xPath - the XPath expression
      s - the XML source to apply the expression to
      Returns:
      matching nodes
    • evaluate

      public String evaluate(String xPath, Source s)
      Evaluates an XPath expression and stringifies the result.
      Specified by:
      evaluate in interface XPathEngine
      Parameters:
      xPath - the XPath expression
      s - the XML source to apply the expression to
      Returns:
      stringified result
    • selectNodes

      public Iterable<Node> selectNodes(String xPath, Node n)
      Returns a potentially empty collection of Nodes matching an XPath expression.
      Specified by:
      selectNodes in interface XPathEngine
      Parameters:
      xPath - the XPath expression
      n - the XML source to apply the expression to
      Returns:
      matching nodes
    • evaluate

      public String evaluate(String xPath, Node n)
      Evaluates an XPath expression and stringifies the result.
      Specified by:
      evaluate in interface XPathEngine
      Parameters:
      xPath - the XPath expression
      n - the XML source to apply the expression to
      Returns:
      stringified result
    • setNamespaceContext

      public void setNamespaceContext(Map<String,String> prefix2Uri)
      Establish a namespace context.
      Specified by:
      setNamespaceContext in interface XPathEngine
      Parameters:
      prefix2Uri - maps from prefix to namespace URI.