Interface XPathExpression


public interface XPathExpression
Defines the contract for a precompiled XPath expression. Concrete instances can be obtained through the XPathExpressionFactory.

Implementations of this interface are precompiled, and thus faster, but less flexible, than the XPath expressions used by XPathOperations implementations.

Since:
1.0.0
Author:
Arjen Poutsma
  • Method Details

    • evaluateAsBoolean

      boolean evaluateAsBoolean(Node node) throws XPathException
      Evaluates the given expression as a boolean. Returns the boolean evaluation of the expression, or false if it is invalid.

      The return value is determined per the boolean() function defined in the XPath specification. This means that an expression that selects zero nodes will return false, while an expression that selects one or more nodes will return true. An expression that returns a string returns false for empty strings and true for all other strings. An expression that returns a number returns false for zero and true for non-zero numbers.

      Parameters:
      node - the starting point
      Returns:
      the result of the evaluation
      Throws:
      XPathException - in case of XPath errors
      See Also:
    • evaluateAsNode

      Node evaluateAsNode(Node node) throws XPathException
      Evaluates the given expression as a Node. Returns the evaluation of the expression, or null if it is invalid.
      Parameters:
      node - the starting point
      Returns:
      the result of the evaluation
      Throws:
      XPathException - in case of XPath errors
      See Also:
    • evaluateAsNodeList

      List<Node> evaluateAsNodeList(Node node) throws XPathException
      Evaluates the given expression, and returns all Node objects that conform to it. Returns an empty list if no result could be found.
      Parameters:
      node - the starting point
      Returns:
      a list of Nodes that are selected by the expression
      Throws:
      XPathException - in case of XPath errors
      See Also:
    • evaluateAsNumber

      double evaluateAsNumber(Node node) throws XPathException
      Evaluates the given expression as a number (double). Returns the numeric evaluation of the expression, or Double.NaN if it is invalid.

      The return value is determined per the number() function as defined in the XPath specification. This means that if the expression selects multiple nodes, it will return the number value of the first node.

      Parameters:
      node - the starting point
      Returns:
      the result of the evaluation
      Throws:
      XPathException - in case of XPath errors
      See Also:
    • evaluateAsString

      String evaluateAsString(Node node) throws XPathException
      Evaluates the given expression as a String. Returns null if no result could be found.

      The return value is determined per the string() function as defined in the XPath specification. This means that if the expression selects multiple nodes, it will return the string value of the first node.

      Parameters:
      node - the starting point
      Returns:
      the result of the evaluation
      Throws:
      XPathException - in case of XPath errors
      See Also:
    • evaluateAsObject

      <T> T evaluateAsObject(Node node, NodeMapper<T> nodeMapper) throws XPathException
      Evaluates the given expression, mapping a single Node result to a Java object via a NodeMapper.
      Parameters:
      node - the starting point
      nodeMapper - object that will map one object per node
      Returns:
      the single mapped object
      Throws:
      XPathException - in case of XPath errors
      See Also:
    • evaluate

      <T> List<T> evaluate(Node node, NodeMapper<T> nodeMapper) throws XPathException
      Evaluates the given expression, mapping each result Node objects to a Java object via a NodeMapper.
      Parameters:
      node - the starting point
      nodeMapper - object that will map one object per node
      Returns:
      the result list, containing mapped objects
      Throws:
      XPathException - in case of XPath errors
      See Also: