# XPath

public interface **XPath** <br />

`XPath` provides access to the XPath evaluation environment and expressions.

| 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 `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathVariableResolver.html` set with `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#setXPathVariableResolver(javax.xml.xpath.XPathVariableResolver)`. An `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathExpressionException.html` 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. <br /> |
| functions | If the expression contains a function reference, the function will be found through the `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathFunctionResolver.html` set with `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#setXPathFunctionResolver(javax.xml.xpath.XPathFunctionResolver)`. An `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathExpressionException.html` is raised if the function resolver is undefined or the function resolver returns `null` for the function. <br /> |
| QNames | QNames in the expression are resolved against the XPath namespace context set with `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#setNamespaceContext(javax.xml.namespace.NamespaceContext)`. |
| result | This result of evaluating an expression is converted to an instance of the desired return type. Valid return types are defined in `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html`. Conversion to the return type follows XPath conversion rules. <br /> |

<br />

##### See Also

- [XML Path Language (XPath) Version 1.0](http://www.w3.org/TR/xpath)

### Public Method Summary

|---|---|
| abstract [XPathExpression](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathExpression.html) | [compile](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#compile(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) expression) Compile an XPath expression for later evaluation. |
| abstract [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [evaluate](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#evaluate(java.lang.String,%20java.lang.Object,%20javax.xml.namespace.QName))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) expression, [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) item, [QName](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/namespace/QName.html) returnType) Evaluate an `XPath` expression in the specified context and return the result as the specified type. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [evaluate](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#evaluate(java.lang.String,%20java.lang.Object))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) expression, [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) item) Evaluate an XPath expression in the specified context and return the result as a `String`. |
| abstract [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [evaluate](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#evaluate(java.lang.String,%20org.xml.sax.InputSource,%20javax.xml.namespace.QName))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) expression, [InputSource](https://developers.google.com/j2objc/javadoc/jre/reference/org/xml/sax/InputSource.html) source, [QName](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/namespace/QName.html) returnType) Evaluate an XPath expression in the context of the specified `InputSource` and return the result as the specified type. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [evaluate](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#evaluate(java.lang.String,%20org.xml.sax.InputSource))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) expression, [InputSource](https://developers.google.com/j2objc/javadoc/jre/reference/org/xml/sax/InputSource.html) source) Evaluate an XPath expression in the context of the specified `InputSource` and return the result as a `String`. |
| abstract [NamespaceContext](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/namespace/NamespaceContext.html) | [getNamespaceContext](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#getNamespaceContext())() Return the current namespace context. |
| abstract [XPathFunctionResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathFunctionResolver.html) | [getXPathFunctionResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#getXPathFunctionResolver())() Return the current function resolver. |
| abstract [XPathVariableResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathVariableResolver.html) | [getXPathVariableResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#getXPathVariableResolver())() Return the current variable resolver. |
| abstract void | [reset](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#reset())() Reset this `XPath` to its original configuration. |
| abstract void | [setNamespaceContext](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#setNamespaceContext(javax.xml.namespace.NamespaceContext))([NamespaceContext](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/namespace/NamespaceContext.html) nsContext) Establish a namespace context. |
| abstract void | [setXPathFunctionResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#setXPathFunctionResolver(javax.xml.xpath.XPathFunctionResolver))([XPathFunctionResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathFunctionResolver.html) resolver) Establish a function resolver. |
| abstract void | [setXPathVariableResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#setXPathVariableResolver(javax.xml.xpath.XPathVariableResolver))([XPathVariableResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathVariableResolver.html) resolver) Establish a variable resolver. |

## Public Methods

#### public abstract [XPathExpression](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathExpression.html)
**compile**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) expression)

<br />

Compile an XPath expression for later evaluation.

If `expression` contains any `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathFunction.html`s,
they must be available via the `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathFunctionResolver.html`.
An `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathExpressionException.html` will be thrown if the `XPathFunction`
cannot be resolved with the `XPathFunctionResolver`.

If `expression` is `null`, a `NullPointerException` is thrown.

<br />

##### Parameters

| expression | The XPath expression. |
|---|---|

##### Returns

- Compiled XPath expression.

##### Throws

| [XPathExpressionException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathExpressionException.html) | If `expression` cannot be compiled. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | If `expression` is `null`. |
|---|---|

#### public abstract [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)
**evaluate**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) expression, [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) item, [QName](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/namespace/QName.html) returnType)

<br />

Evaluate an `XPath` expression in the specified context and return the result as the specified type.

See [Evaluation of XPath Expressions](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath#XPath-evaluation) for context item evaluation,
variable, function and `QName` resolution and return type conversion.

If `returnType` is not one of the types defined in `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html` (
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html#NUMBER`,
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html#STRING`,
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html#BOOLEAN`,
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html#NODE` or
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html#NODESET`)
then an `IllegalArgumentException` is thrown.

If a `null` value is provided for
`item`, an empty document will be used for the
context.
If `expression` or `returnType` is `null`, then a
`NullPointerException` is thrown.

<br />

##### Parameters

| expression | The XPath expression. |
| item | The starting context (node or node list, for example). |
| returnType | The desired return type. |
|---|---|

##### Returns

- Result of evaluating an XPath expression as an `Object` of `returnType`.

##### Throws

| [XPathExpressionException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathExpressionException.html) | If `expression` cannot be evaluated. |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If `returnType` is not one of the types defined in `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html`. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | If `expression` or `returnType` is `null`. |
|---|---|

#### public abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**evaluate**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) expression, [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) item)

<br />

Evaluate an XPath expression in the specified context and return the result as a `String`.

This method calls `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#evaluate(java.lang.String,%20java.lang.Object,%20javax.xml.namespace.QName)` with a `returnType` of
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html#STRING`.

See [Evaluation of XPath Expressions](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath#XPath-evaluation) for context item evaluation,
variable, function and QName resolution and return type conversion.

If a `null` value is provided for
`item`, an empty document will be used for the
context.
If `expression` is `null`, then a `NullPointerException` is thrown.

<br />

##### Parameters

| expression | The XPath expression. |
| item | The starting context (node or node list, for example). |
|---|---|

##### Returns

- The `String` that is the result of evaluating the expression and converting the result to a `String`.

##### Throws

| [XPathExpressionException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathExpressionException.html) | If `expression` cannot be evaluated. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | If `expression` is `null`. |
|---|---|

#### public abstract [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)
**evaluate**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) expression, [InputSource](https://developers.google.com/j2objc/javadoc/jre/reference/org/xml/sax/InputSource.html) source, [QName](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/namespace/QName.html) returnType)

<br />

Evaluate an XPath expression in the context of the specified `InputSource`
and return the result as the specified type.

This method builds a data model for the `https://developers.google.com/j2objc/javadoc/jre/reference/org/xml/sax/InputSource.html` and calls
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#evaluate(java.lang.String,%20java.lang.Object,%20javax.xml.namespace.QName)` on the resulting document object.

See [Evaluation of XPath Expressions](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath#XPath-evaluation) for context item evaluation,
variable, function and QName resolution and return type conversion.

If `returnType` is not one of the types defined in `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html`,
then an `IllegalArgumentException` is thrown.

If `expression`, `source` or `returnType` is `null`,
then a `NullPointerException` is thrown.

<br />

##### Parameters

| expression | The XPath expression. |
| source | The input source of the document to evaluate over. |
| returnType | The desired return type. |
|---|---|

##### Returns

- The `Object` that encapsulates the result of evaluating the expression.

##### Throws

| [XPathExpressionException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathExpressionException.html) | If expression cannot be evaluated. |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If `returnType` is not one of the types defined in `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html`. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | If `expression`, `source` or `returnType` is `null`. |
|---|---|

#### public abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**evaluate**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) expression, [InputSource](https://developers.google.com/j2objc/javadoc/jre/reference/org/xml/sax/InputSource.html) source)

<br />

Evaluate an XPath expression in the context of the specified `InputSource`
and return the result as a `String`.

This method calls `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath.html#evaluate(java.lang.String,%20org.xml.sax.InputSource,%20javax.xml.namespace.QName)` with a
`returnType` of `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathConstants.html#STRING`.

See [Evaluation of XPath Expressions](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPath#XPath-evaluation) for context item evaluation,
variable, function and QName resolution and return type conversion.

If `expression` or `source` is `null`,
then a `NullPointerException` is thrown.

<br />

##### Parameters

| expression | The XPath expression. |
| source | The `InputSource` of the document to evaluate over. |
|---|---|

##### Returns

- The `String` that is the result of evaluating the expression and converting the result to a `String`.

##### Throws

| [XPathExpressionException](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathExpressionException.html) | If expression cannot be evaluated. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | If `expression` or `source` is `null`. |
|---|---|

#### public abstract [NamespaceContext](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/namespace/NamespaceContext.html)
**getNamespaceContext**
()

<br />

Return the current namespace context.

`null` is returned in no namespace context is in effect.

<br />

##### Returns

- Current Namespace context.

#### public abstract [XPathFunctionResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathFunctionResolver.html)
**getXPathFunctionResolver**
()

<br />

Return the current function resolver.

`null` is returned in no function resolver is in effect.

<br />

##### Returns

- Current function resolver.

#### public abstract [XPathVariableResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathVariableResolver.html)
**getXPathVariableResolver**
()

<br />

Return the current variable resolver.

`null` is returned in no variable resolver is in effect.

<br />

##### Returns

- Current variable resolver.

#### public abstract void
**reset**
()

<br />

Reset this `XPath` to its original configuration.

`XPath` is reset to the same state as when it was created with
`https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathFactory.html#newXPath()`.
`reset()` is designed to allow the reuse of existing `XPath`s
thus saving resources associated with the creation of new `XPath`s.

The reset `XPath` is not guaranteed to have the same `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathFunctionResolver.html`, `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathVariableResolver.html`
or `https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/namespace/NamespaceContext.html` `Object`s, e.g. `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object)`.
It is guaranteed to have a functionally equal `XPathFunctionResolver`, `XPathVariableResolver`
and `NamespaceContext`.

<br />

#### public abstract void
**setNamespaceContext**
([NamespaceContext](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/namespace/NamespaceContext.html) nsContext)

<br />

Establish a namespace context.

A `NullPointerException` is thrown if `nsContext` is `null`.

<br />

##### Parameters

| nsContext | Namespace context to use. |
|---|---|

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | If `nsContext` is `null`. |
|---|---|

#### public abstract void
**setXPathFunctionResolver**
([XPathFunctionResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathFunctionResolver.html) resolver)

<br />

Establish a function resolver.

A `NullPointerException` is thrown if `resolver` is `null`.

<br />

##### Parameters

| resolver | XPath function resolver. |
|---|---|

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | If `resolver` is `null`. |
|---|---|

#### public abstract void
**setXPathVariableResolver**
([XPathVariableResolver](https://developers.google.com/j2objc/javadoc/jre/reference/javax/xml/xpath/XPathVariableResolver.html) resolver)

<br />

Establish a variable resolver.

A `NullPointerException` is thrown if `resolver` is `null`.

<br />

##### Parameters

| resolver | Variable resolver. |
|---|---|

##### Throws

| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | If `resolver` is `null`. |
|---|---|