Class XPathContext
Provides namespace prefix bindings for use in an XPath expression.
- Version:
- 1.3.1
- Author:
- Elliotte Rusty Harold
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new XPath context that binds thexml
prefix to the URIhttp://www.w3.org/XML/1998/namespace
.XPathContext
(String prefix, String uri) Creates a new XPath context that binds the specified prefix to the specified URI. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNamespace
(String prefix, String uri) Binds the specified prefix to the specified namespace URI.Returns the namespace URI associated with a specified prefix in this context.static XPathContext
makeNamespaceContext
(Element element) Creates a new XPath context that contains all the namespace bindings in scope on the element.
-
Constructor Details
-
XPathContext
Creates a new XPath context that binds the specified prefix to the specified URI. The
xml
prefix is also bound to the URIhttp://www.w3.org/XML/1998/namespace
.- Parameters:
prefix
- the prefix to binduri
- the namespace URI the prefix is bound to
-
XPathContext
public XPathContext()Creates a new XPath context that binds the
xml
prefix to the URIhttp://www.w3.org/XML/1998/namespace
.
-
-
Method Details
-
addNamespace
Binds the specified prefix to the specified namespace URI. If the prefix is already bound in this context, the new URI replaces the old URI. Binding a prefix to null removes the declaration. The binding of the
xml
prefix may not be changed.- Parameters:
prefix
- the prefix to binduri
- the namespace URI the prefix is bound to- Throws:
NamespaceConflictException
- if the prefix isxml
and the URI is nothttp://www.w3.org/XML/1998/namespace
or the prefix is the empty stringNullPointerException
- if the prefix is null
-
makeNamespaceContext
Creates a new XPath context that contains all the namespace bindings in scope on the element. Changing the prefixes in scope on the element after the context is returned does not change the context.
- Parameters:
element
- the element whose namespace bindings are copied- Returns:
- all the namespace prefix mappings in scope on the element
-
lookup
Returns the namespace URI associated with a specified prefix in this context. It returns null if this prefix is not bound to a namespace in this context. The prefix is not checked for validity. If you pass in a prefix that is not an NCName, this method simply returns null.- Parameters:
prefix
- the prefix to look up- Returns:
- the namespace URI associated with the specified prefix in this context or null
-