Interface XPathExpression
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
-
Method Summary
Modifier and TypeMethodDescription<T> List<T> evaluate(Node node, NodeMapper<T> nodeMapper) Evaluates the given expression, mapping each resultNodeobjects to a Java object via aNodeMapper.booleanevaluateAsBoolean(Node node) Evaluates the given expression as aboolean.@Nullable NodeevaluateAsNode(Node node) Evaluates the given expression as aNode.evaluateAsNodeList(Node node) Evaluates the given expression, and returns allNodeobjects that conform to it.doubleevaluateAsNumber(Node node) Evaluates the given expression as a number (double).<T> @Nullable TevaluateAsObject(Node node, NodeMapper<T> nodeMapper) Evaluates the given expression, mapping a singleNoderesult to a Java object via aNodeMapper.@Nullable StringevaluateAsString(Node node) Evaluates the given expression as a String.
-
Method Details
-
evaluateAsBoolean
Evaluates the given expression as aboolean. Returns the boolean evaluation of the expression, orfalseif 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 returnfalse, while an expression that selects one or more nodes will returntrue. An expression that returns a string returnsfalsefor empty strings andtruefor all other strings. An expression that returns a number returnsfalsefor zero andtruefor non-zero numbers.- Parameters:
node- the starting point- Returns:
- the result of the evaluation
- Throws:
XPathException- in case of XPath errors- See Also:
-
evaluateAsNode
Evaluates the given expression as aNode. Returns the evaluation of the expression, ornullif it is invalid.- Parameters:
node- the starting point- Returns:
- the result of the evaluation
- Throws:
XPathException- in case of XPath errors- See Also:
-
evaluateAsNodeList
Evaluates the given expression, and returns allNodeobjects 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
Evaluates the given expression as a number (double). Returns the numeric evaluation of the expression, orDouble.NaNif 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
Evaluates the given expression as a String. Returnsnullif 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
Evaluates the given expression, mapping a singleNoderesult to a Java object via aNodeMapper.- Parameters:
node- the starting pointnodeMapper- object that will map one object per node- Returns:
- the single mapped object
- Throws:
XPathException- in case of XPath errors- See Also:
-
evaluate
Evaluates the given expression, mapping each resultNodeobjects to a Java object via aNodeMapper.- Parameters:
node- the starting pointnodeMapper- object that will map one object per node- Returns:
- the result list, containing mapped objects
- Throws:
XPathException- in case of XPath errors- See Also:
-