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. |
公共方法(Public methods) |
|
|---|---|
abstract XPathExpression |
compile(String expression) 编译XPath表达式以供以后评估。 |
abstract Object |
evaluate(String expression, Object item, QName returnType) 在指定的上下文中评估 |
abstract String |
evaluate(String expression, Object item) 在指定的上下文中评估XPath表达式并将结果作为 |
abstract Object |
evaluate(String expression, InputSource source, QName returnType) 在指定的 |
abstract String |
evaluate(String expression, InputSource source) 在指定的 |
abstract NamespaceContext |
getNamespaceContext() 返回当前名称空间上下文。 |
abstract XPathFunctionResolver |
getXPathFunctionResolver() 返回当前函数解析器。 |
abstract XPathVariableResolver |
getXPathVariableResolver() 返回当前的变量解析器。 |
abstract void |
reset() 将此 |
abstract void |
setNamespaceContext(NamespaceContext nsContext) 建立一个名称空间上下文。 |
abstract void |
setXPathFunctionResolver(XPathFunctionResolver resolver) 建立一个功能解析器。 |
abstract void |
setXPathVariableResolver(XPathVariableResolver resolver) 建立一个变量解析器。 |
XPathExpression compile (String expression)
编译XPath表达式以供以后评估。
如果expression包含任何XPathFunction ,则它们必须通过XPathFunctionResolver 。 一个XPathExpressionException将被抛出,如果XPathFunction不能与解决XPathFunctionResolver 。
如果 expression是 null ,则引发 NullPointerException 。
| 参数(Parameters) | |
|---|---|
expression |
String: The XPath expression. |
| 返回(Returns) | |
|---|---|
XPathExpression |
Compiled XPath expression. |
| 抛出异常(Throws) | |
|---|---|
XPathExpressionException |
If expression cannot be compiled. |
NullPointerException |
If expression is null. |
Object evaluate (String expression, Object item, QName returnType)
在指定的上下文中评估 XPath表达式,并将结果作为指定的类型返回。
有关上下文项评估,变量,函数和 QName分辨率和返回类型转换,请参见 Evaluation of XPath Expressions 。
如果 returnType不在定义的类型的一个 XPathConstants ( NUMBER , STRING , BOOLEAN , NODE或 NODESET )那么 IllegalArgumentException被抛出。
如果null提供了一种用于值item ,一个空文档将被用于的上下文。 如果expression或returnType是null ,则引发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. |
String evaluate (String expression, Object item)
在指定的上下文中评估XPath表达式,并将结果作为 String返回。
此方法调用 evaluate(String, Object, QName)具有 returnType的 STRING 。
有关上下文项评估,变量,函数和QName解析以及返回类型转换,请参见 Evaluation of XPath Expressions 。
如果null提供了一种用于值item ,一个空文档将被用于的上下文。 如果expression是null ,则引发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. |
Object evaluate (String expression, InputSource source, QName returnType)
在指定的 InputSource的上下文中评估XPath表达式,并将结果作为指定的类型返回。
此方法为 InputSource构建数据模型,并在生成的文档对象上调用 evaluate(String, Object, QName) 。
有关上下文项评估,变量,函数和QName解析以及返回类型转换,请参见 Evaluation of XPath Expressions 。
如果 returnType不在定义的类型之一 XPathConstants ,那么 IllegalArgumentException被抛出。
如果 expression , source或者 returnType为 null ,则 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. |
String evaluate (String expression, InputSource source)
在指定的 InputSource的上下文中评估XPath表达式,并将结果返回为 String 。
此方法调用 evaluate(String, InputSource, QName)具有 returnType的 STRING 。
有关上下文项评估,变量,函数和QName解析以及返回类型转换,请参见 Evaluation of XPath Expressions 。
如果 expression或 source是 null ,则引发 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. |
NamespaceContext getNamespaceContext ()
返回当前名称空间上下文。
null在没有名称空间上下文有效的情况下返回。
| 返回(Returns) | |
|---|---|
NamespaceContext |
Current Namespace context. |
XPathFunctionResolver getXPathFunctionResolver ()
返回当前函数解析器。
null在没有函数解析器生效的情况下返回。
| 返回(Returns) | |
|---|---|
XPathFunctionResolver |
Current function resolver. |
XPathVariableResolver getXPathVariableResolver ()
返回当前的变量解析器。
null在没有变量解析器有效时返回。
| 返回(Returns) | |
|---|---|
XPathVariableResolver |
Current variable resolver. |
void reset ()
将此 XPath重置为其原始配置。
XPath被重置为与使用newXPath()创建时相同的状态。 reset()旨在允许重复使用现有的XPath从而节省与创建新的XPath相关的资源。
复位XPath不能保证具有相同XPathFunctionResolver , XPathVariableResolver或者NamespaceContext Object S,如equals(Object) 。 但保证具有功能相等XPathFunctionResolver , XPathVariableResolver和NamespaceContext 。
void setNamespaceContext (NamespaceContext nsContext)
建立一个名称空间上下文。
一个 NullPointerException如果抛出 nsContext为 null 。
| 参数(Parameters) | |
|---|---|
nsContext |
NamespaceContext: Namespace context to use. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
If nsContext is null. |
void setXPathFunctionResolver (XPathFunctionResolver resolver)
建立一个功能解析器。
一个 NullPointerException如果抛出 resolver为 null 。
| 参数(Parameters) | |
|---|---|
resolver |
XPathFunctionResolver: XPath function resolver. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
If resolver is null. |
void setXPathVariableResolver (XPathVariableResolver resolver)
建立一个变量解析器。
一个 NullPointerException如果抛出 resolver为 null 。
| 参数(Parameters) | |
|---|---|
resolver |
XPathVariableResolver: Variable resolver. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
If resolver is null. |