Most visited

Recently visited

Added in API level 8

XPathFactory

public abstract class XPathFactory
extends Object

java.lang.Object
   ↳ javax.xml.xpath.XPathFactory


一个 XPathFactory实例可用于创建 XPath对象。

有关查找机制,请参见 newInstance(String)

Summary

Constants

String DEFAULT_OBJECT_MODEL_URI

默认对象模型URI。

String DEFAULT_PROPERTY_NAME

根据JAXP规范的默认属性名称。

Protected constructors

XPathFactory()

受保护的构造为 newInstance()newInstance(String)或者 newInstance(String, String, ClassLoader)应该被用于创建的新实例 XPathFactory

Public methods

abstract boolean getFeature(String name)

获取指定功能的状态。

abstract boolean isObjectModelSupported(String objectModel)

XPathFactory是否支持指定的对象模型?

static final XPathFactory newInstance()

使用默认对象模型 DEFAULT_OBJECT_MODEL_URI获取新的 XPathFactory实例,即W3C DOM。

static XPathFactory newInstance(String uri, String factoryClassName, ClassLoader classLoader)
static final XPathFactory newInstance(String uri)

使用指定的对象模型获取新的 XPathFactory实例。

abstract XPath newXPath()

使用实例化 XPathFactory时确定的基础对象模型返回新的 XPath

abstract void setFeature(String name, boolean value)

为此工厂创建的 XPathFactoryXPath设置一个功能。

abstract void setXPathFunctionResolver(XPathFunctionResolver resolver)

建立一个默认的功能解析器。

abstract void setXPathVariableResolver(XPathVariableResolver resolver)

建立一个默认变量解析器。

Inherited methods

From class java.lang.Object

Constants

DEFAULT_OBJECT_MODEL_URI

Added in API level 8
String DEFAULT_OBJECT_MODEL_URI

默认对象模型URI。

常量值:“http://java.sun.com/jaxp/xpath/dom”

DEFAULT_PROPERTY_NAME

Added in API level 8
String DEFAULT_PROPERTY_NAME

根据JAXP规范的默认属性名称。

常量值:“javax.xml.xpath.XPathFactory”

Protected constructors

XPathFactory

Added in API level 8
XPathFactory ()

受保护的构造为 newInstance()newInstance(String)或者 newInstance(String, String, ClassLoader)应该被用于创建的新实例 XPathFactory

Public methods

getFeature

Added in API level 8
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 XPaths it creates cannot support this feature.
NullPointerException if name is null.

isObjectModelSupported

Added in API level 8
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.

newInstance

Added in API level 8
XPathFactory newInstance ()

使用默认对象模型 DEFAULT_OBJECT_MODEL_URI (W3C DOM)获取新的 XPathFactory实例。

此方法在功能上等同于:

   newInstance(DEFAULT_OBJECT_MODEL_URI)
 

由于W3C DOM的实现始终可用,因此此方法永远不会失败。

Returns
XPathFactory Instance of an XPathFactory.

newInstance

Added in API level 8
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.

newInstance

Added in API level 8
XPathFactory newInstance (String uri)

使用指定的对象模型获取新的 XPathFactory实例。

要查找 XPathFactory对象,此方法按以下顺序查找以下位置,其中“类加载器”引用上下文类加载器:

  1. If the system property 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.
  2. ${java.home}/lib/jaxp.properties is read and the value associated with the key being the system property above is looked for. If present, the value is processed just like above.
  3. The class loader is asked for service provider provider-configuration files matching 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.
  4. Platform default 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.

newXPath

Added in API level 8
XPath newXPath ()

使用实例化 XPathFactory时确定的基础对象模型返回新的 XPath

Returns
XPath New instance of an XPath.

setFeature

Added in API level 8
void setFeature (String name, 
                boolean value)

设置此工厂创建的此 XPathFactoryXPath的功能。

功能名称完全限定为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 XPaths it creates cannot support this feature.
NullPointerException if name is null.

setXPathFunctionResolver

Added in API level 8
void setXPathFunctionResolver (XPathFunctionResolver resolver)

建立一个默认的功能解析器。

从该工厂构造的任何 XPath对象将默认使用指定的解析器。

一个 NullPointerException如果抛出 resolvernull

Parameters
resolver XPathFunctionResolver: XPath function resolver.
Throws
NullPointerException If resolver is null.

setXPathVariableResolver

Added in API level 8
void setXPathVariableResolver (XPathVariableResolver resolver)

建立一个默认变量解析器。

从该工厂构造的任何 XPath对象将默认使用指定的解析器。

一个 NullPointerException如果抛出 resolvernull

Parameters
resolver XPathVariableResolver: Variable resolver.
Throws
NullPointerException If resolver is null.

Hooray!