nu.xom

Class 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.1b3
Author:
Elliotte Rusty Harold

Field Summary

static String
XML_NAMESPACE
Namespace URI specified for xml prefix

Constructor Summary

Namespace(String prefix, String URI, Element parent)
Create a new namespace node.

Method Summary

Node
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.

Methods inherited from class nu.xom.Node

copy, detach, equals, getBaseURI, getChild, getChildCount, getDocument, getParent, getValue, hashCode, query, query, toXML

Field Details

XML_NAMESPACE

public static final String XML_NAMESPACE
Namespace URI specified for xml prefix

Constructor Details

Namespace

public Namespace(String prefix,
                 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 name
URI - the namespace URI
parent - the element that possesses this namespace node

Method Details

copy

public Node copy()
Returns a copy of this namespace which has the same prefix and URI, but no parent.
Overrides:
copy in interface Node
Returns:
a copy of this Namespace that is not part of a document

detach

public void detach()
Removes this namespace node from its parent.
Overrides:
detach in interface Node
See Also:
Node.detach()

getChild

public Node getChild(int position)
Throws IndexOutOfBoundsException because namespaces do not have children.
Overrides:
getChild in interface Node
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.

getChildCount

public int getChildCount()
Returns 0 because namespaces do not have children.
Overrides:
getChildCount in interface Node
Returns:
zero

getPrefix

public String getPrefix()
Returns the namespace prefix, or the empty string if this node is the default namespace.
Returns:
the namespace prefix

getValue

public String getValue()
Returns the namespace URI.
Overrides:
getValue in interface Node
Returns:
the namespace URI

toString

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.
Returns:
a string representation of this object

toXML

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/".
Overrides:
toXML in interface Node
Returns:
a String containing an XML namespace declaration

Copyright 2002-2005 Elliotte Rusty Harold
elharo@metalab.unc.edu