Most visited

Recently visited

Added in API level 8

XPathExpression

public interface XPathExpression

javax.xml.xpath.XPathExpression


XPathExpression提供对编译的XPath表达式的访问。

Evaluation of XPath Expressions.
context If a request is made to evaluate the expression in the absence of a context item, an empty document node will be used for the context. For the purposes of evaluating XPath expressions, a DocumentFragment is treated like a Document node.
variables If the expression contains a variable reference, its value will be found through the XPathVariableResolver. An XPathExpressionException is raised if the variable resolver is undefined or the resolver returns null for the variable. The value of a variable must be immutable through the course of any single evaluation.

functions If the expression contains a function reference, the function will be found through the XPathFunctionResolver. An XPathExpressionException is raised if the function resolver is undefined or the function resolver returns null for the function.

QNames QNames in the expression are resolved against the XPath namespace context.
result This result of evaluating an expression is converted to an instance of the desired return type. Valid return types are defined in XPathConstants. Conversion to the return type follows XPath conversion rules.

也可以看看:

Summary

Public methods

abstract String evaluate(Object item)

在指定的上下文中评估编译的XPath表达式,并以 String返回结果。

abstract String evaluate(InputSource source)

在指定的 InputSource的上下文中评估编译的XPath表达式,并将结果返回为 String

abstract Object evaluate(InputSource source, QName returnType)

在指定的 InputSource的上下文中评估编译的XPath表达式,并将结果作为指定的类型返回。

abstract Object evaluate(Object item, QName returnType)

在指定的上下文中评估编译的XPath表达式,并返回结果作为指定的类型。

Public methods

evaluate

Added in API level 8
String evaluate (Object item)

在指定的上下文中评估编译的XPath表达式,并将结果返回为 String

此方法调用 evaluate(Object, QName)具有 returnTypeSTRING

有关上下文项评估,变量,函数和QName解析以及返回类型转换,请参见 Evaluation of XPath Expressions

如果 null提供了一种用于值 item ,一个空文档将被用于的上下文。

Parameters
item Object: The starting context (node or node list, for example).
Returns
String The String that is the result of evaluating the expression and converting the result to a String.
Throws
XPathExpressionException If the expression cannot be evaluated.

evaluate

Added in API level 8
String evaluate (InputSource source)

在指定的 InputSource的上下文中评估编译的XPath表达式,并将结果作为 String返回。

此方法调用 evaluate(InputSource, QName)具有 returnTypeSTRING

有关上下文项评估,变量,函数和QName解析以及返回类型转换,请参见 Evaluation of XPath Expressions

如果 sourcenull ,则引发 NullPointerException

Parameters
source InputSource: The InputSource of the document to evaluate over.
Returns
String The String that is the result of evaluating the expression and converting the result to a String.
Throws
XPathExpressionException If the expression cannot be evaluated.
NullPointerException If source is null.

evaluate

Added in API level 8
Object evaluate (InputSource source, 
                QName returnType)

在指定的 InputSource的上下文中评估编译的XPath表达式,并将结果作为指定的类型返回。

此方法为 InputSource构建数据模型,并在生成的文档对象上调用 evaluate(Object, QName)

有关上下文项评估,变量,函数和QName解析以及返回类型转换,请参见 Evaluation of XPath Expressions

如果 returnType不在定义的类型之一 XPathConstants ,那么 IllegalArgumentException被抛出。

如果 sourcereturnTypenull ,则引发 NullPointerException

Parameters
source InputSource: The InputSource of the document to evaluate over.
returnType QName: The desired return type.
Returns
Object The Object that is the result of evaluating the expression and converting the result to returnType.
Throws
XPathExpressionException If the expression cannot be evaluated.
IllegalArgumentException If returnType is not one of the types defined in XPathConstants.
NullPointerException If source or returnType is null.

evaluate

Added in API level 8
Object evaluate (Object item, 
                QName returnType)

在指定的上下文中评估编译的XPath表达式,并返回结果作为指定的类型。

有关上下文项评估,变量,函数和QName解析以及返回类型转换,请参见 Evaluation of XPath Expressions

如果 returnType不在定义的类型之一 XPathConstants ,那么 IllegalArgumentException被抛出。

If a null value is provided for item, an empty document will be used for the context. If returnType is null, then a NullPointerException is thrown.

Parameters
item Object: The starting context (node or node list, for example).
returnType QName: The desired return type.
Returns
Object The Object that is the result of evaluating the expression and converting the result to returnType.
Throws
XPathExpressionException If the expression cannot be evaluated.
IllegalArgumentException If returnType is not one of the types defined in XPathConstants.
NullPointerException If returnType is null.

Hooray!