Most visited

Recently visited

Added in API level 8

XPath

public interface XPath

javax.xml.xpath.XPath


XPath提供对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 set with setXPathVariableResolver(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 set with setXPathFunctionResolver(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 set with setNamespaceContext(NamespaceContext).
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 XPathExpression compile(String expression)

编译XPath表达式以供以后评估。

abstract Object evaluate(String expression, Object item, QName returnType)

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

abstract String evaluate(String expression, Object item)

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

abstract Object evaluate(String expression, InputSource source, QName returnType)

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

abstract String evaluate(String expression, InputSource source)

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

abstract NamespaceContext getNamespaceContext()

返回当前名称空间上下文。

abstract XPathFunctionResolver getXPathFunctionResolver()

返回当前函数解析器。

abstract XPathVariableResolver getXPathVariableResolver()

返回当前的变量解析器。

abstract void reset()

将此 XPath重置为其原始配置。

abstract void setNamespaceContext(NamespaceContext nsContext)

建立一个名称空间上下文。

abstract void setXPathFunctionResolver(XPathFunctionResolver resolver)

建立一个功能解析器。

abstract void setXPathVariableResolver(XPathVariableResolver resolver)

建立一个变量解析器。

Public methods

compile

Added in API level 8
XPathExpression compile (String expression)

编译XPath表达式以供以后评估。

如果expression包含任何XPathFunction ,则它们必须通过XPathFunctionResolver 一个XPathExpressionException将被抛出,如果XPathFunction不能与解决XPathFunctionResolver

如果 expressionnull ,则引发 NullPointerException

Parameters
expression String: The XPath expression.
Returns
XPathExpression Compiled XPath expression.
Throws
XPathExpressionException If expression cannot be compiled.
NullPointerException If expression is null.

evaluate

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

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

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

如果 returnType不在定义的类型的一个 XPathConstantsNUMBERSTRINGBOOLEANNODENODESET )那么 IllegalArgumentException被抛出。

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

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

evaluate

Added in API level 8
String evaluate (String expression, 
                Object item)

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

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

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

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

Parameters
expression String: The XPath expression.
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 expression cannot be evaluated.
NullPointerException If expression is null.

evaluate

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

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

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

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

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

如果 expressionsource或者 returnTypenull ,则 NullPointerException被抛出。

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

evaluate

Added in API level 8
String evaluate (String expression, 
                InputSource source)

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

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

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

如果 expressionsourcenull ,则引发 NullPointerException

Parameters
expression String: The XPath expression.
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 expression cannot be evaluated.
NullPointerException If expression or source is null.

getNamespaceContext

Added in API level 8
NamespaceContext getNamespaceContext ()

返回当前名称空间上下文。

null在没有名称空间上下文有效的情况下返回。

Returns
NamespaceContext Current Namespace context.

getXPathFunctionResolver

Added in API level 8
XPathFunctionResolver getXPathFunctionResolver ()

返回当前函数解析器。

null在没有函数解析器生效的情况下返回。

Returns
XPathFunctionResolver Current function resolver.

getXPathVariableResolver

Added in API level 8
XPathVariableResolver getXPathVariableResolver ()

返回当前的变量解析器。

null在没有变量解析器有效时返回。

Returns
XPathVariableResolver Current variable resolver.

reset

Added in API level 8
void reset ()

将此 XPath重置为其原始配置。

XPath被重置为与使用newXPath()创建时相同的状态。 reset()旨在允许重复使用现有的XPath从而节省与创建新的XPath相关的资源。

复位XPath不能保证具有相同XPathFunctionResolverXPathVariableResolver或者NamespaceContext Object S,如equals(Object) 但保证具有功能相等XPathFunctionResolverXPathVariableResolverNamespaceContext

setNamespaceContext

Added in API level 8
void setNamespaceContext (NamespaceContext nsContext)

建立一个名称空间上下文。

一个 NullPointerException如果抛出 nsContextnull

Parameters
nsContext NamespaceContext: Namespace context to use.
Throws
NullPointerException If nsContext is null.

setXPathFunctionResolver

Added in API level 8
void setXPathFunctionResolver (XPathFunctionResolver resolver)

建立一个功能解析器。

一个 NullPointerException如果抛出 resolvernull

Parameters
resolver XPathFunctionResolver: XPath function resolver.
Throws
NullPointerException If resolver is null.

setXPathVariableResolver

Added in API level 8
void setXPathVariableResolver (XPathVariableResolver resolver)

建立一个变量解析器。

一个 NullPointerException如果抛出 resolvernull

Parameters
resolver XPathVariableResolver: Variable resolver.
Throws
NullPointerException If resolver is null.

Hooray!