Interface XPathOperations
- All Known Implementing Classes:
AbstractXPathTemplate
,JaxenXPathTemplate
,Jaxp13XPathTemplate
The templates that implement this interface do not use precompiled XPath expressions. Consider using the
XPathExpressionFactory
or the XPathExpressionFactoryBean
for optimal performance, but less
flexibility.
- Since:
- 1.0.0
- Author:
- Arjen Poutsma
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
evaluate
(String expression, Source context, NodeCallbackHandler callbackHandler) Evaluates the given expression, handling the resultNode
objects on a per-node basis with aNodeCallbackHandler
.<T> List<T>
evaluate
(String expression, Source context, NodeMapper<T> nodeMapper) Evaluates the given expression, mapping each resultNode
objects to a Java object via aNodeMapper
.boolean
evaluateAsBoolean
(String expression, Source context) Evaluates the given expression as aboolean
.double
evaluateAsDouble
(String expression, Source context) Evaluates the given expression as adouble
.evaluateAsNode
(String expression, Source context) Evaluates the given expression as aNode
.evaluateAsNodeList
(String expression, Source context) Evaluates the given expression as a list ofNode
objects.<T> T
evaluateAsObject
(String expression, Source context, NodeMapper<T> nodeMapper) Evaluates the given expression, mapping a singleNode
result to a Java object via aNodeMapper
.evaluateAsString
(String expression, Source context) Evaluates the given expression as aString
.
-
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:
expression
- the XPath expressioncontext
- the context 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:
expression
- the XPath expressioncontext
- the context starting point- Returns:
- the result of the evaluation
- Throws:
XPathException
- in case of XPath errors- See Also:
-
evaluateAsNodeList
Evaluates the given expression as a list ofNode
objects. Returns the evaluation of the expression, or an empty list if no results are found.- Parameters:
expression
- the XPath expressioncontext
- the context starting point- Returns:
- the result of the evaluation
- Throws:
XPathException
- in case of XPath errors- See Also:
-
evaluateAsDouble
Evaluates the given expression as adouble
. Returns the 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:
expression
- the XPath expressioncontext
- the context starting point- Returns:
- the result of the evaluation
- Throws:
XPathException
- in case of XPath errors- See Also:
-
evaluateAsString
Evaluates the given expression as aString
. Returns the evaluation of the expression, ornull
if it is invalid.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:
expression
- the XPath expressioncontext
- the context starting point- Returns:
- the result of the evaluation
- Throws:
XPathException
- in case of XPath errors- See Also:
-
evaluateAsObject
<T> T evaluateAsObject(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException Evaluates the given expression, mapping a singleNode
result to a Java object via aNodeMapper
.- Parameters:
expression
- the XPath expressioncontext
- the context 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
<T> List<T> evaluate(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException Evaluates the given expression, mapping each resultNode
objects to a Java object via aNodeMapper
.- Parameters:
expression
- the XPath expressioncontext
- the context 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:
-
evaluate
void evaluate(String expression, Source context, NodeCallbackHandler callbackHandler) throws XPathException Evaluates the given expression, handling the resultNode
objects on a per-node basis with aNodeCallbackHandler
.- Parameters:
expression
- the XPath expressioncontext
- the context starting pointcallbackHandler
- object that will extract results, one row at a time- Throws:
XPathException
- in case of XPath errors- See Also:
-