Class XPathFactory

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

public abstract class XPathFactory extends Object

An XPathFactory instance can be used to create XPath objects.

See newInstance(String uri) for lookup mechanism.

The XPathFactory class is not thread-safe. In other words, it is the application's responsibility to ensure that at most one thread is using a XPathFactory object at any given moment. Implementations are encouraged to mark methods as synchronized to protect themselves from broken clients.

XPathFactory is not re-entrant. While one of the newInstance methods is being invoked, applications may not attempt to recursively invoke a newInstance method, even from the same thread.

Since:
1.5
  • Field Details

    • DEFAULT_PROPERTY_NAME

      public static final String DEFAULT_PROPERTY_NAME

      The default property name according to the JAXP spec.

      See Also:
    • DEFAULT_OBJECT_MODEL_URI

      public static final String DEFAULT_OBJECT_MODEL_URI

      Default Object Model URI.

      See Also:
  • Constructor Details

  • Method Details

    • newDefaultInstance

      public static XPathFactory newDefaultInstance()
      Creates a new instance of the XPathFactory builtin system-default implementation.
      Implementation Requirements:
      The XPathFactory builtin system-default implementation is only required to support the default object model, the W3C DOM, but may support additional object models.
      Returns:
      A new instance of the XPathFactory builtin system-default implementation.
      Since:
      9
    • newInstance

      public static XPathFactory newInstance()

      Get a new XPathFactory instance using the default object model, DEFAULT_OBJECT_MODEL_URI, the W3C DOM.

      This method is functionally equivalent to:

         newInstance(DEFAULT_OBJECT_MODEL_URI)
       

      Since the implementation for the W3C DOM is always available, this method will never fail.

      Returns:
      Instance of an XPathFactory.
      Throws:
      RuntimeException - When there is a failure in creating an XPathFactory for the default object model.
    • newInstance

      public static XPathFactory newInstance(String uri) throws XPathFactoryConfigurationException
      Obtains a new XPathFactory instance using the specified object model. This method uses the JAXP Lookup Mechanism to determine and load the XPathFactory implementation that supports the specified object model.

      Tip for Trouble-shooting:

      See Properties.load(java.io.InputStream) for exactly how a property file is parsed. In particular, colons ':' need to be escaped in a property file, so make sure the URIs are properly escaped in it. For example:

         http\://java.sun.com/jaxp/xpath/dom=org.acme.DomXPathFactory
       

      Parameters:
      uri - 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:
      Instance of an XPathFactory.
      Throws:
      XPathFactoryConfigurationException - If the specified object model is unavailable, or if there is a configuration error.
      NullPointerException - If uri is null.
      IllegalArgumentException - If uri is null or uri.length() == 0.
    • newInstance

      public static XPathFactory newInstance(String uri, String factoryClassName,