public abstract class XPathFactory
extends Object
java.lang.Object | |
↳ | javax.xml.xpath.XPathFactory |
一个 XPathFactory
实例可用于创建 XPath
对象。
有关查找机制,请参见 newInstance(String)
。
Constants |
|
---|---|
String |
DEFAULT_OBJECT_MODEL_URI 默认对象模型URI。 |
String |
DEFAULT_PROPERTY_NAME 根据JAXP规范的默认属性名称。 |
Protected constructors |
|
---|---|
XPathFactory() 受保护的构造为 |
Public methods |
|
---|---|
abstract boolean |
getFeature(String name) 获取指定功能的状态。 |
abstract boolean |
isObjectModelSupported(String objectModel) 此 |
static final XPathFactory |
newInstance() 使用默认对象模型 |
static XPathFactory |
newInstance(String uri, String factoryClassName, ClassLoader classLoader) |
static final XPathFactory |
newInstance(String uri) 使用指定的对象模型获取新的 |
abstract XPath |
newXPath() 使用实例化 |
abstract void |
setFeature(String name, boolean value) 为此工厂创建的 |
abstract void |
setXPathFunctionResolver(XPathFunctionResolver resolver) 建立一个默认的功能解析器。 |
abstract void |
setXPathVariableResolver(XPathVariableResolver resolver) 建立一个默认变量解析器。 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
String DEFAULT_OBJECT_MODEL_URI
默认对象模型URI。
常量值:“http://java.sun.com/jaxp/xpath/dom”
String DEFAULT_PROPERTY_NAME
根据JAXP规范的默认属性名称。
常量值:“javax.xml.xpath.XPathFactory”
XPathFactory ()
受保护的构造为 newInstance()
, newInstance(String)
或者 newInstance(String, String, ClassLoader)
应该被用于创建的新实例 XPathFactory
。
boolean getFeature (String name)
获取指定功能的状态。
功能名称完全符合URI
s。 实现可以定义它们自己的特征。 一个XPathFactoryConfigurationException
如果这是抛出XPathFactory
或者XPath
的IT创建不支持该功能。 XPathFactory
可能会公开某个特征值,但无法更改其状态。
Parameters | |
---|---|
name |
String : Feature name. |
Returns | |
---|---|
boolean |
State of the named feature. |
Throws | |
---|---|
XPathFactoryConfigurationException |
if this XPathFactory or the XPath s it creates cannot support this feature. |
NullPointerException |
if name is null . |
boolean isObjectModelSupported (String objectModel)
此 XPathFactory
是否支持指定的对象模型?
Parameters | |
---|---|
objectModel |
String : Specifies the object model which the returned XPathFactory will understand. |
Returns | |
---|---|
boolean |
true if XPathFactory supports objectModel , else false . |
Throws | |
---|---|
NullPointerException |
If objectModel is null . |
IllegalArgumentException |
If objectModel.length() == 0 . |
XPathFactory newInstance ()
使用默认对象模型 DEFAULT_OBJECT_MODEL_URI
(W3C DOM)获取新的 XPathFactory
实例。
此方法在功能上等同于:
newInstance(DEFAULT_OBJECT_MODEL_URI)
由于W3C DOM的实现始终可用,因此此方法永远不会失败。
Returns | |
---|---|
XPathFactory |
Instance of an XPathFactory . |
XPathFactory newInstance (String uri, String factoryClassName, ClassLoader classLoader)
Parameters | |
---|---|
uri |
String
|
factoryClassName |
String
|
classLoader |
ClassLoader
|
Returns | |
---|---|
XPathFactory |
Instance of an XPathFactory . |
Throws | |
---|---|
XPathFactoryConfigurationException |
If the specified object model is unavailable. |
NullPointerException |
If uri is null . |
IllegalArgumentException |
If uri.length() == 0 . |
XPathFactory newInstance (String uri)
使用指定的对象模型获取新的 XPathFactory
实例。
要查找 XPathFactory
对象,此方法按以下顺序查找以下位置,其中“类加载器”引用上下文类加载器:
DEFAULT_PROPERTY_NAME
+ ":uri" is present, where uri is the parameter to this method, then its value is read as a class name. The method will try to create a new instance of this class by using the class loader, and returns it if it is successfully created. javax.xml.xpath.XPathFactory
in the resource directory META-INF/services. See the JAR File Specification for file format and parsing rules. Each potential service provider is required to implement the method:
isObjectModelSupported(String)
The first service provider found in class loader order that supports the specified object model is returned. XPathFactory
is located in a platform specific way. There must be a platform default XPathFactory for the W3C DOM, i.e. DEFAULT_OBJECT_MODEL_URI
. 如果一切都失败了,将会抛出 XPathFactoryConfigurationException
。
故障排除提示:
有关如何分析属性文件的信息,请参见load(java.io.InputStream)
。 特别是,冒号':'需要在属性文件中转义,因此请确保URI正确地转义。 例如:
http\://java.sun.com/jaxp/xpath/dom=org.acme.DomXPathFactory
Parameters | |
---|---|
uri |
String : Identifies the underlying object model. The specification only defines the URI DEFAULT_OBJECT_MODEL_URI , http://java.sun.com/jaxp/xpath/dom for the W3C DOM, the org.w3c.dom package, and implementations are free to introduce other URIs for other object models. |
Returns | |
---|---|
XPathFactory |
Instance of an XPathFactory . |
Throws | |
---|---|
XPathFactoryConfigurationException |
If the specified object model is unavailable. |
NullPointerException |
If uri is null . |
IllegalArgumentException |
If uri.length() == 0 . |
XPath newXPath ()
使用实例化 XPathFactory
时确定的基础对象模型返回新的 XPath
。
Returns | |
---|---|
XPath |
New instance of an XPath . |
void setFeature (String name, boolean value)
设置此工厂创建的此 XPathFactory
和 XPath
的功能。
功能名称完全限定为URI
s。 实现可以定义它们自己的特征。 一个XPathFactoryConfigurationException
如果这是抛出XPathFactory
或者XPath
的IT创建不支持该功能。 XPathFactory
可能会公开某个特征值,但无法更改其状态。
所有实现都需要支持FEATURE_SECURE_PROCESSING
功能。 当功能是true
,对外部功能的任何引用都是错误的。 在这些条件下,执行不得调用XPathFunctionResolver
并且必须抛出XPathFunctionException
。
Parameters | |
---|---|
name |
String : Feature name. |
value |
boolean : Is feature state true or false . |
Throws | |
---|---|
XPathFactoryConfigurationException |
if this XPathFactory or the XPath s it creates cannot support this feature. |
NullPointerException |
if name is null . |
void setXPathFunctionResolver (XPathFunctionResolver resolver)
建立一个默认的功能解析器。
从该工厂构造的任何 XPath
对象将默认使用指定的解析器。
一个 NullPointerException
如果抛出 resolver
为 null
。
Parameters | |
---|---|
resolver |
XPathFunctionResolver : XPath function resolver. |
Throws | |
---|---|
NullPointerException |
If resolver is null . |
void setXPathVariableResolver (XPathVariableResolver resolver)
建立一个默认变量解析器。
从该工厂构造的任何 XPath
对象将默认使用指定的解析器。
一个 NullPointerException
如果抛出 resolver
为 null
。
Parameters | |
---|---|
resolver |
XPathVariableResolver : Variable resolver. |
Throws | |
---|---|
NullPointerException |
If resolver is null . |