JDOM does not extend the core Java XPath API (javax.xml.xpath.XPath). Instead it creates a new API that is more JDOM and Java friendly leading to neater and more understandable code (in a JDOM context).
A JDOM XPathFactory instance is able to create JDOM XPathExpression instances that can be used to evaluate XPath expressions against JDOM Content.
The XPathFactory allows either default or custom XPathFactory instances to be
created. If you use the newInstance(String) method then an
XPathFactory of that specific type will be created. If you use the
instance() method then a default XPathFactory instance will be
returned.
Instances of XPathFactory are specified to be thread-safe. You can reuse an XPathFactory in multiple threads. Instances of XPathExpression are NOT thread-safe.
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final AtomicReference | defaultreference
An atomic reference storing an instance of the default XPathFactory. |
| private static final Namespace[] |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract < The generic type of the results that the XPathExpression will
produce. T> XPathExpression | Returns: an XPathExpression<> instance.The XPath expression. expression, Filter<T> The Filter that is used to coerce the XPath result data in to the
generic-typed results.
Note that the filter, Map<String, Object> Filters class has a number of predefined, useful
filters.Any variable values that may be referenced from the query. A null
value indicates that there are no variables. variables, Namespace... Any namespaces that may be referenced from the query namespaces)Create a Compiled XPathExpression<> instance from this factory. |
| public < The generic type of the results that the XPathExpression will
produce. T> XPathExpression | Returns: an XPathExpression<T> instance.The XPath expression. expression, Filter<T> The Filter that is used to coerce the xpath result data in to the
generic-typed results.
Note that the filter, Map<String, Object> Filters class has a number of predefined, useful
filters.Any variable values that may be referenced from the query. A null
value indicates that there are no variables. variables, Collection<Namespace> List of all namespaces that may be referenced from the query namespaces)Create a XPathExpression<> instance from this factory. |
| public < The generic type of the results that the XPathExpression will
produce. T> XPathExpression | Returns: an XPathExpression<T> instance.The XPath expression. expression, Filter<T> The Filter that is used to coerce the xpath result data in to the
generic-typed results.
Note that the filter)Filters class has a number of predefined, useful
filters.Create a XPathExpression<T> instance from this factory. |
| public XPathExpression | |
| public static final XPathFactory | Returns: the default XPathFactory instanceObtain an instance of an XPathFactory using the default mechanisms to determine what XPathFactory implementation to use. |
| public static final XPathFactory | Returns: An XPathFactory of the specified class.The name of the XPathFactory class to create. factoryclass)Create a new instance of an explicit XPathFactory. |
| DEFAULTFACTORY | back to summary |
|---|---|
| private static final String DEFAULTFACTORY | |
| defaultreference | back to summary |
|---|---|
| private static final AtomicReference<XPathFactory> defaultreference An atomic reference storing an instance of the default XPathFactory. | |
| EMPTYNS | back to summary |
|---|---|
| private static final Namespace[] EMPTYNS | |
| XPathFactory | back to summary |
|---|---|
| public XPathFactory() | |
| compile | back to summary |
|---|---|
| public abstract <T> XPathExpression Create a Compiled XPathExpression<> instance from this factory. This is the only abstract method on this class. All other compile and evaluate methods prepare the data in some way to call this compile method. XPathFactory implementations override this method to implement support for the JDOM/XPath API.
A Filter is used to coerce resulting XPath data in to a suitable JDOM generic
type. Note that the
NamespaceXPath expressions are always namespace aware, and expect to be able to resolve prefixes to namespace URIs. In XPath expressions the prefix "" always resolves to the empty Namespace URI "". A prefix in an XPath query is expected to resolve to exactly one URI. Multiple different prefixes in the expression may resolve to the same URI.This compile method ensures that these XPath/Namespace rules are followed and thus this method will throw IllegalArgumentException if:
Variables
Variables are referenced from XPath expressions using a
This compile method expects all variable names to be expressed in a prefix-qualified format, where all prefixes have to be available in one of the specified Namespace instances.
e.g. if you specify a variable name "ns:var" with value "value", you also
need to have some namespace provided with the prefix "ns" such as
Some XPath libraries allow null variable values (Jaxen), some do not
(native Java). This compile method will silently convert any null
Variable value to an empty string Variables are provided in the form of a Map where the key is the variable name and the mapped value is the variable value. If the entire map is null then the compile Method assumes there are no variables. In light of the above, this compile method will throw an IllegalArgumentException if:
| |
| compile | back to summary |
|---|---|
| public <T> XPathExpression Create a XPathExpression<> instance from this factory.
| |
| compile | back to summary |
|---|---|
| public <T> XPathExpression Create a XPathExpression<T> instance from this factory.
| |
| compile | back to summary |
|---|---|
| public XPathExpression Create a XPathExpression<Object> instance from this factory.
| |
| instance | back to summary |
|---|---|
| public static final XPathFactory instance() Obtain an instance of an XPathFactory using the default mechanisms to determine what XPathFactory implementation to use. The exact same XPathFactory instance will be returned from each call.
The default mechanism will inspect the system property (only once)
| |
| newInstance | back to summary |
|---|---|
| public static final XPathFactory newInstance(String factoryclass) Create a new instance of an explicit XPathFactory. A new instance of the specified XPathFactory is created each time. The target XPathFactory needs to have a no-argument default constructor.
This method is a convenience mechanism only, and JDOM users are free to
create a custom XPathFactory instance and use a simple:
| |