public interface 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 resolver). 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 resolver). 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 nsContext). |
| 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对象不是线程安全的,不可重入的。换句话说,它是应用程序的责任,确保一个XPath对象不是用来从多个线程在任何给定的时间,而evaluate方法被调用时,应用程序可能不evaluate递归调用的方法。
| Modifier and Type | Method and Description |
|---|---|
XPathExpression |
compile(String expression)
编译后的评估一个XPath表达式。
|
String |
evaluate(String expression, InputSource source)
评估在特定的语境
InputSource XPath表达式作为一个
String返回结果。
|
Object |
evaluate(String expression, InputSource source, QName returnType)
评估在特定的语境
InputSource XPath表达式,指定类型的返回结果。
|
String |
evaluate(String expression, Object item)
评估指定上下文中的XPath表达式作为一个
String返回结果。
|
Object |
evaluate(String expression, Object item, QName returnType)
评估在指定上下文的一个
XPath表达为指定类型的返回结果。
|
NamespaceContext |
getNamespaceContext()
返回当前命名空间上下文。
|
XPathFunctionResolver |
getXPathFunctionResolver()
返回当前函数旋转变压器。
|
XPathVariableResolver |
getXPathVariableResolver()
返回当前变量解析器。
|
void |
reset()
这
XPath复位到原来的配置。
|
void |
setNamespaceContext(NamespaceContext nsContext)
建立命名空间上下文。
|
void |
setXPathFunctionResolver(XPathFunctionResolver resolver)
建立一个功能解析。
|
void |
setXPathVariableResolver(XPathVariableResolver resolver)
建立一个变量解析器。
|
void reset()
这XPath复位到原来的配置。
XPath设置为相同的状态时,它的创建与XPathFactory.newXPath()。reset()旨在让现有的XPaths节约与新XPaths创作相关资源的重用。
复位XPath不能保证有相同的XPathFunctionResolver,XPathVariableResolver或NamespaceContext Objects,例如Object.equals(Object obj)。这是保证有一个功能相同的XPathFunctionResolver,XPathVariableResolver和NamespaceContext。
void setXPathVariableResolver(XPathVariableResolver resolver)
建立一个变量解析器。
如果一个NullPointerException resolver是null扔。
resolver变量解析器。
null
resolver
NullPointerException。
XPathVariableResolver getXPathVariableResolver()
返回当前变量解析器。
null没有变量解析器返回的是影响。
void setXPathFunctionResolver(XPathFunctionResolver resolver)
建立一个功能解析。
如果一个NullPointerException resolver是null扔。
resolver - XPath函数旋转变压器。
null
resolver
NullPointerException。
XPathFunctionResolver getXPathFunctionResolver()
返回当前函数旋转变压器。
null是没有功能的解析器返回的是影响。
void setNamespaceContext(NamespaceContext nsContext)
建立命名空间上下文。
如果一个NullPointerException nsContext是null扔。
nsContext -命名空间上下文使用。
null
nsContext
NullPointerException。
NamespaceContext getNamespaceContext()
返回当前命名空间上下文。
null没有命名空间上下文返回实际上是。
XPathExpression compile(String expression) throws XPathExpressionException
编译后的评估一个XPath表达式。
如果expression包含任何XPathFunctions,他们必须通过XPathFunctionResolver。一个XPathExpressionException将如果XPathFunction不能解决的XPathFunctionResolver扔。
如果expression包含任何变量的影响,XPathVariableResolver 在编译的时候将用于解决。
如果expression是null,一NullPointerException抛出。
expression的XPath表达式。
XPathExpressionException -如果
expression不能编译。
null
expression
NullPointerException。
Object evaluate(String expression, Object item, QName returnType) throws XPathExpressionException
评估在指定上下文的一个XPath表达为指定类型的返回结果。
看到背景的项目评估,Evaluation of XPath Expressions变量、函数和QName分辨率和返回类型转换。
如果returnType不是一XPathConstants中定义的类型(NUMBER,STRING,BOOLEAN,NODE或NODESET)然后IllegalArgumentException抛出。
如果一个null值提供给item,空文件将用于上下文。如果expression或returnType是null,然后NullPointerException抛出。
expression的XPath表达式。
item -启动上下文(例如一个节点,)。
returnType -预期的返回类型。
Object
returnType结果。
XPathExpressionException -如果
expression无法评估。
IllegalArgumentException -如果
returnType不是一
XPathConstants中定义的类型。
NullPointerException -如果
expression或
returnType是
null。
String evaluate(String expression, Object item) throws XPathExpressionException
评估指定上下文中的XPath表达式作为一个String返回结果。
此方法调用evaluate(String expression, Object item, QName returnType)与returnType的XPathConstants.STRING。
看到背景的项目评估,Evaluation of XPath Expressions变量、函数和属性的分辨率和返回类型转换。
如果一个null值提供给item,空文件将用于上下文。如果expression是null,然后NullPointerException抛出。
expression的XPath表达式。
item -启动上下文(例如一个节点,)。
String表达和转换的结果到一个
String结果。
XPathExpressionException -如果
expression无法评估。
null
expression
NullPointerException。
Object evaluate(String expression, InputSource source, QName returnType) throws XPathExpressionException
评估在特定的语境InputSource XPath表达式,指定类型的返回结果。
这种方法建立的InputSource数据模型和调用此文档对象evaluate(String expression, Object item, QName returnType)。
看到背景的项目评估,Evaluation of XPath Expressions变量、函数和属性的分辨率和返回类型转换。
如果returnType不是一XPathConstants中定义的类型,然后IllegalArgumentException抛出。
如果expression,source或returnType是null,然后NullPointerException抛出。
expression的XPath表达式。
source -文档评估输入源。
returnType -预期的返回类型。
Object概括评价结果的表达。
XPathExpressionException如果无法计算表达式。
IllegalArgumentException -如果
returnType不是一
XPathConstants中定义的类型。
NullPointerException -如果
expression,
source或
returnType是
null。
String evaluate(String expression, InputSource source) throws XPathExpressionException
评估在特定的语境InputSource XPath表达式作为一个String返回结果。
此方法调用evaluate(String expression, InputSource source, QName returnType)与returnType的XPathConstants.STRING。
看到背景的项目评估,Evaluation of XPath Expressions变量、函数和属性的分辨率和返回类型转换。
如果expression或source是null,然后NullPointerException抛出。
expression的XPath表达式。
source -文档评价在
InputSource。
String表达和转换的结果到一个
String结果。
XPathExpressionException如果无法计算表达式。
NullPointerException -如果
expression或
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.