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()
旨在让现有的XPath
s节约与新XPath
s创作相关资源的重用。
复位XPath
不能保证有相同的XPathFunctionResolver
,XPathVariableResolver
或NamespaceContext
Object
s,例如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
包含任何XPathFunction
s,他们必须通过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.