public final class XPathContext
extends Object
Provides namespace prefix bindings for use in an XPath expression.
Constructor and Description |
---|
XPathContext()
Creates a new XPath context that binds the
xml
prefix to the URI
http://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.
|
Modifier and Type | Method and Description |
---|---|
void | addNamespace(String prefix,
String uri)
Binds the specified prefix to the specified namespace URI.
|
String | lookup(String prefix)
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.
|
public XPathContext(String prefix, String uri)
Creates a new XPath context that binds the specified prefix to
the specified URI. The xml
prefix is also bound to the URI
http://www.w3.org/XML/1998/namespace
.
prefix
- the prefix to binduri
- the namespace URI the prefix is bound topublic XPathContext()
Creates a new XPath context that binds the xml
prefix to the URI
http://www.w3.org/XML/1998/namespace
.
public void addNamespace(String prefix, String uri)
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.
prefix
- the prefix to binduri
- the namespace URI the prefix is bound toNamespaceConflictException
- if the prefix is
xml
and the URI is not
http://www.w3.org/XML/1998/namespace
or the
prefix is the empty stringNullPointerException
- if the prefix is nullpublic static XPathContext makeNamespaceContext(Element element)
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.
element
- the element whose namespace bindings are copiedpublic String lookup(String prefix)
prefix
- the prefix to look upCopyright 2002-2023 Elliotte Rusty Harold
elharo@ibiblio.org