Class Namespace
- java.lang.Object
-
- nu.xom.Node
-
- nu.xom.Namespace
-
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.)
- Version:
- 1.3.0
- Author:
- Elliotte Rusty Harold
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringXML_NAMESPACENamespace URI specified forxmlprefix
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Namespacecopy()Returns a copy of this namespace which has the same prefix and URI, but no parent.voiddetach()Removes this namespace node from its parent.NodegetChild(int position)ThrowsIndexOutOfBoundsExceptionbecause namespaces do not have children.intgetChildCount()Returns 0 because namespaces do not have children.java.lang.StringgetPrefix()Returns the namespace prefix, or the empty string if this node is the default namespace.java.lang.StringgetValue()Returns the namespace URI.java.lang.StringtoString()Returns a string form of theNamespacesuitable for debugging and diagnosis.java.lang.StringtoXML()Returns a string containing the actual XML form of the namespace declaration represented by this object.-
Methods inherited from class nu.xom.Node
equals, getBaseURI, getDocument, getParent, hashCode, query, query
-
-
-
-
Field Detail
-
XML_NAMESPACE
public static final java.lang.String XML_NAMESPACE
Namespace URI specified forxmlprefix- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Namespace
public Namespace(java.lang.String prefix, java.lang.String URI, Element parent)Create a new namespace node.
- Parameters:
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 node- Throws:
MalformedURIException- ifURIis not an RFC 3986 URI referenceIllegalNameException- if- The prefix is
xmlns. - The prefix is not the empty string, and the URI is null or the empty string.
- The prefix is
NamespaceConflictException- if- The prefix is the empty string, and the URI is null or the empty string.
- The prefix is
xml, and the URI is nothttp://www.w3.org/XML/1998/namespace. - The prefix is not
xml, and the URI ishttp://www.w3.org/XML/1998/namespace.
-
-
Method Detail
-
getPrefix
public java.lang.String getPrefix()
Returns the namespace prefix, or the empty string if this node is the default namespace.
- Returns:
- the namespace prefix
-
getValue
public java.lang.String getValue()
Returns the namespace URI.
-
getChild
public Node getChild(int position)
Throws
IndexOutOfBoundsExceptionbecause namespaces do not have children.- Specified by:
getChildin classNode- Parameters:
position- the index of the child node to return- Returns:
- never returns because document type declarations do not have children. Always throws an exception.
- Throws:
java.lang.IndexOutOfBoundsException- because document type declarations do not have children
-
getChildCount
public int getChildCount()
Returns 0 because namespaces do not have children.
- Specified by:
getChildCountin classNode- Returns:
- zero
-
copy
public Namespace copy()
Returns a copy of this namespace which has the same prefix and URI, but no parent.
-
detach
public void detach()
Removes this namespace node from its parent.
- Overrides:
detachin classNode- See Also:
Node.detach()
-
toXML
public java.lang.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/".
-
toString
public java.lang.String toString()
Returns a string form of the
Namespacesuitable for debugging and diagnosis. It deliberately does not return an actual XML namespace declaration.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of this object
-
-