public interface XPathExpression
XPathExpression提供对编译的XPath表达式的访问。
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.
XPath表达式不是线程安全的,不可重入。 换句话说,应用程序的责任是确保在任何给定时间从多个线程中使用一个XPathExpression对象,并且当调用evaluate方法时,应用程序可能不递归调用evaluate方法。
| Modifier and Type | Method and Description |
|---|---|
String |
evaluate(InputSource source)
计算指定的上下文中,编译的XPath表达式
InputSource并返回结果作为
String 。
|
Object |
evaluate(InputSource source, QName returnType)
计算指定的上下文中,编译的XPath表达式
InputSource并返回其结果作为指定的类型。
|
String |
evaluate(Object item)
在指定的上下文中评估编译的XPath表达式,并将结果作为
String 。
|
Object |
evaluate(Object item, QName returnType)
在指定的上下文中评估编译的XPath表达式,并将结果作为指定的类型返回。
|
Object evaluate(Object item, QName returnType) throws XPathExpressionException
在指定的上下文中评估编译的XPath表达式,并将结果作为指定的类型返回。
见Evaluation of XPath Expressions上下文项计算,变量,函数和QName解析,以及返回类型转换。
如果returnType不是returnType中定义的类型之一 ,则抛出一个IllegalArgumentException 。
如果null被提供用于值item ,一个空文档将被用于的上下文。 如果returnType是null ,那么会抛出一个NullPointerException 。
item - 起始上下文(例如一个节点)。
returnType - 所需的返回类型。
Object是评估表达式并将结果转换为
returnType的结果。
XPathExpressionException - 如果表达式无法评估。
IllegalArgumentException - 如果returnType不是returnType中定义的类型之一 。
NullPointerException - 如果
returnType是
null 。
String evaluate(Object item) throws XPathExpressionException
在指定的上下文中评估编译的XPath表达式,并将结果作为String 。
该方法调用evaluate(Object item, QName returnType)与returnType的XPathConstants.STRING 。
见Evaluation of XPath Expressions上下文项计算,变量,函数和QName解析,以及返回类型转换。
如果null被提供用于值item ,一个空文档将被用于的上下文。
item - 起始上下文(例如一个节点)。
String是评估表达式并将结果转换为
String的结果。
XPathExpressionException - 如果表达式无法评估。
Object evaluate(InputSource source, QName returnType) throws XPathExpressionException
计算指定的上下文中,编译的XPath表达式InputSource并返回其结果作为指定的类型。
此方法为InputSource构建数据模型,并在结果文档对象上调用evaluate(Object item, QName returnType) 。
见Evaluation of XPath Expressions上下文项计算,变量,函数和QName解析,以及返回类型转换。
如果returnType不是returnType中定义的类型之一 ,那么抛出一个IllegalArgumentException 。
如果source或returnType是null ,那么抛出一个NullPointerException 。
source - 评估文件的
InputSource 。
returnType - 所需的返回类型。
Object是评估表达式并将结果转换为
returnType的结果。
XPathExpressionException - 如果表达式无法评估。
IllegalArgumentException - 如果returnType不是returnType中定义的类型之一 。
NullPointerException - 如果
source或
returnType是
null 。
String evaluate(InputSource source) throws XPathExpressionException
计算指定的上下文中,编译的XPath表达式InputSource并返回结果作为String 。
该方法调用evaluate(InputSource source, QName returnType)与returnType的XPathConstants.STRING 。
见Evaluation of XPath Expressions上下文项计算,变量,函数和QName解析,以及返回类型转换。
如果source是null ,那么会抛出一个NullPointerException 。
source - 评估文件的
InputSource 。
String是评估表达式并将结果转换为
String的结果。
XPathExpressionException - 如果表达式无法评估。
NullPointerException - 如果
source是
null 。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.