public final class Namespace extends Node
Represents a namespace in scope. It is used by XOM's XPath implementation for the namespace axis. However, it is not really part of the XOM data model. Namespace objects are only created as needed when evaluating XPath. While a namespace node has a parent element (which may be null), that element does not know about these namespace nodes and cannot remove them. (This is an inconsistency in the XPath data model, and is shared with attributes which also have parents but are not children.)
Modifier and Type | Field and Description |
---|---|
static String | XML_NAMESPACE
Namespace URI specified for
xml prefix |
Constructor and Description |
---|
Namespace(String prefix,
String URI,
Element parent)
Create a new namespace node.
|
Modifier and Type | Method and Description |
---|---|
Namespace | copy()
Returns a copy of this namespace which has
the same prefix and URI, but no parent.
|
void | detach()
Removes this namespace node from its parent.
|
Node | getChild(int position)
Throws
IndexOutOfBoundsException because
namespaces do not have children. |
int | getChildCount()
Returns 0 because namespaces do not have
children.
|
String | getPrefix()
Returns the namespace prefix, or the empty string if this node
is the default namespace.
|
String | getValue()
Returns the namespace URI.
|
String | toString()
Returns a string form of the
Namespace suitable for debugging
and diagnosis. |
String | toXML()
Returns a string containing the actual XML
form of the namespace declaration represented
by this object.
|
equals, getBaseURI, getDocument, getParent, hashCode, query, query
public static final String XML_NAMESPACE
xml
prefixpublic Namespace(String prefix, String URI, Element parent)
Create a new namespace node.
prefix
- the prefix for the namespace; may be the empty
string or a non-colonized nameURI
- the namespace URIparent
- the element that possesses this namespace nodeMalformedURIException
- if URI
is
not an RFC 3986 URI referenceIllegalNameException
- if
xmlns
.NamespaceConflictException
- if
xml
, and the URI is not
http://www.w3.org/XML/1998/namespace
.xml
, and the URI is
http://www.w3.org/XML/1998/namespace
.public String getPrefix()
Returns the namespace prefix, or the empty string if this node is the default namespace.
public String getValue()
Returns the namespace URI.
public Node getChild(int position)
Throws IndexOutOfBoundsException
because
namespaces do not have children.
public int getChildCount()
Returns 0 because namespaces do not have children.
getChildCount
in class Node
public Namespace copy()
Returns a copy of this namespace which has the same prefix and URI, but no parent.
public void detach()
Removes this namespace node from its parent.
detach
in class Node
Node.detach()
public String toXML()
Returns a string containing the actual XML
form of the namespace declaration represented
by this object. For example,
xmlns:pre="http://www.example.org/"
.
public String toString()
Returns a string form of the
Namespace
suitable for debugging
and diagnosis. It deliberately does not return
an actual XML namespace declaration.
toString
in class Object
Copyright 2002-2023 Elliotte Rusty Harold
elharo@ibiblio.org