Evaluate an XPath
expression in the specified context and return the result as the specified type.
See Evaluation of XPath Expressions for context item evaluation, variable, function and QName
resolution and return type conversion.
If returnType
is not one of the types defined in {@link XPathConstants} ({@link XPathConstants#NUMBER NUMBER}, {@link XPathConstants#STRING STRING}, {@link XPathConstants#BOOLEAN BOOLEAN}, {@link XPathConstants#NODE NODE} or{@link XPathConstants#NODESET NODESET}) then an IllegalArgumentException
is thrown.
If a null
value is provided for item
, an empty document will be used for the context. If expression
or returnType
is null
, then a NullPointerException
is thrown.
@param expression The XPath expression.
@param item The starting context (node or node list, for example).
@param returnType The desired return type.
@return Result of evaluating an XPath expression as an
Object
of
returnType
.
@throws XPathExpressionException If
expression
cannot be evaluated.
@throws IllegalArgumentException If
returnType
is not one of the types defined in {@link XPathConstants}.
@throws NullPointerException If
expression
or
returnType
is
null
.