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
- Author:
- Arjen Poutsma
-
Method Summary
Modifier and TypeMethodDescription<T> List<T>
evaluate
(Node node, NodeMapper<T> nodeMapper) Evaluates the given expression, mapping each resultNode
objects to a Java object via aNodeMapper
.boolean
evaluateAsBoolean
(Node node) Evaluates the given expression as aboolean
.evaluateAsNode
(Node node) Evaluates the given expression as aNode
.evaluateAsNodeList
(Node node) Evaluates the given expression, and returns allNode
objects that conform to it.double
evaluateAsNumber
(Node node) Evaluates the given expression as a number (double
).<T> T
evaluateAsObject
(Node node, NodeMapper<T> nodeMapper) Evaluates the given expression, mapping a singleNode
result to a Java object via aNodeMapper
.evaluateAsString
(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, orfalse
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 returnfalse
, while an expression that selects one or more nodes will returntrue
. An expression that returns a string returnsfalse
for empty strings andtrue
for all other strings. An expression that returns a number returnsfalse
for zero andtrue
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
Evaluates the given expression as aNode
. Returns the evaluation of the expression, ornull
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
Evaluates the given expression, and returns allNode
objects that conform to it. Returns an empty list if no result could be found.- Parameters:
node
- the starting point- Returns:
- a list of
Node
s 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.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
Evaluates the given expression as a String. Returnsnull
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
Evaluates the given expression, mapping a singleNode
result 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 resultNode
objects 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:
-