Class NamespaceNode
- All Implemented Interfaces:
Node
This class implements the DOM2 and DOM3 Node
interface
to allow namespace nodes to be included in the result
set of an XPath selectNodes operation, even though DOM does
not model namespaces in scope as separate nodes.
While all of the DOM2 methods are implemented with reasonable defaults, there will be some unexpected surprises, so users are advised to test for NamespaceNodes and filter them out from the result sets as early as possible.
- The
getNodeType()
method returnsNAMESPACE_NODE
, which is not one of the usual DOM2 node types. Generic code may fall unexpectedly out of switch statements, for example. - The
getOwnerDocument()
method returns the owner document of the parent node, but that owner document will know nothing about the namespace node. - The
isSupported(java.lang.String, java.lang.String)
method always returns false. - The DOM3 methods sometimes throw UnsupportedOperationException. They're here only to allow this class to be compiled with Java 1.5. Do not call or rely on them.
All attempts to modify a NamespaceNode
will fail with a DOMException
(DOMException.NO_MODIFICATION_ALLOWED_ERR
).
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
A node list with no members. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
static final short
Constant: this is a NamespaceNode.private Node
private HashMap
private String
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
-
Constructor Summary
ConstructorsConstructorDescriptionNamespaceNode
(Node parent, String name, String value) Create a new NamespaceNode.NamespaceNode
(Node parent, Node attribute) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionappendChild
(Node newChild) Append a new child node (always fails).cloneNode
(boolean deep) Create a copy of this node.short
compareDocumentPosition
(Node other) Compare relative position of this node to another nbode.private void
Throw a NO_MODIFICATION_ALLOWED_ERR DOMException.boolean
Test for equivalence with another object.private boolean
Helper method for comparing two objects.Get the attribute nodes.Return the base URI of the document containing this node.Get the list of child nodes.getFeature
(String feature, String version) Returns the value of the requested feature.Get the first child node.Get the last child node.Get the XPath name of the namespace node;; i.e.Get the namespace URI of this node.Get the next sibling node.Get the namespace prefix.short
Get the node type.Get the namespace URI.Get the owner document.Get the parent node.Get the namespace prefix of this node.Get the previous sibling node.Return the namespace URI.getUserData
(String key) Returns the user data associated with the given key.boolean
Test if this node has attributes.boolean
Test for child nodes.int
hashCode()
Generate a hash code for a namespace node.private int
Helper method for generating a hash code.insertBefore
(Node newChild, Node refChild) Insert a new child node (always fails).boolean
isDefaultNamespace
(String namespaceURI) Return true if the specified URI is the default namespace in scope (always fails).boolean
isEqualNode
(Node arg) Returns true if this object binds the same prefix to the same URI.boolean
isSameNode
(Node other) Returns true if and only if this object represents the same XPath namespace node as the argument; that is, they have the same parent, the same prefix, and the same URI.boolean
isSupported
(String feature, String version) Test if a DOM2 feature is supported.lookupNamespaceURI
(String prefix) Return the namespace URI mapped to the specified prefix within the scope of this namespace node.lookupPrefix
(String namespaceURI) Return the prefix bound to this namespace URI within the scope of this node.void
Normalize the text descendants of this node.removeChild
(Node oldChild) Remove a child node (always fails).replaceChild
(Node newChild, Node oldChild) Replace a child node (always fails).void
setNodeValue
(String value) Change the namespace URI (always fails).void
Change the namespace prefix of this node (always fails).void
setTextContent
(String textContent) Change the value of this node (always fails).setUserData
(String key, Object data, UserDataHandler handler) Associates an object with a key.
-
Field Details
-
NAMESPACE_NODE
public static final short NAMESPACE_NODEConstant: this is a NamespaceNode.- See Also:
-
parent
-
name
-
value
-
userData
-
-
Constructor Details
-
NamespaceNode
Create a new NamespaceNode.- Parameters:
parent
- the DOM node to which the namespace is attachedname
- the namespace prefixvalue
- the namespace URI
-
NamespaceNode
Constructor.- Parameters:
parent
- the DOM node to which the namespace is attachedattribute
- the DOM attribute object containing the namespace declaration
-
-
Method Details
-
getNodeName
Get the namespace prefix.- Specified by:
getNodeName
in interfaceNode
- Returns:
- the namespace prefix, or "" for the default namespace
-
getNodeValue
Get the namespace URI.- Specified by:
getNodeValue
in interfaceNode
- Returns:
- the namespace URI
-
setNodeValue
Change the namespace URI (always fails).- Specified by:
setNodeValue
in interfaceNode
- Parameters:
value
- the new URI- Throws:
DOMException
- always
-
getNodeType
public short getNodeType()Get the node type.- Specified by:
getNodeType
in interfaceNode
- Returns:
- always
NAMESPACE_NODE
.
-
getParentNode
Get the parent node.This method returns the element that was queried for Namespaces in effect, not necessarily the actual element containing the Namespace declaration.
- Specified by:
getParentNode
in interfaceNode
- Returns:
- the parent node (not null)
-
getChildNodes
Get the list of child nodes.- Specified by:
getChildNodes
in interfaceNode
- Returns:
- an empty node list
-
getFirstChild
Get the first child node.- Specified by:
getFirstChild
in interfaceNode
- Returns:
- null
-
getLastChild
Get the last child node.- Specified by:
getLastChild
in interfaceNode
- Returns:
- null
-
getPreviousSibling
Get the previous sibling node.- Specified by:
getPreviousSibling
in interfaceNode
- Returns:
- null
-
getNextSibling
Get the next sibling node.- Specified by:
getNextSibling
in interfaceNode
- Returns:
- null
-
getAttributes
Get the attribute nodes.- Specified by:
getAttributes
in interfaceNode
- Returns:
- null
-
getOwnerDocument
Get the owner document.- Specified by:
getOwnerDocument
in interfaceNode
- Returns:
- the owner document of the parent node
-
insertBefore
Insert a new child node (always fails).- Specified by:
insertBefore
in interfaceNode
- Parameters:
newChild
- the node to addrefChild
- ignored- Returns:
- never
- Throws:
DOMException
- always- See Also:
-
replaceChild
Replace a child node (always fails).- Specified by:
replaceChild
in interfaceNode
- Parameters:
newChild
- the node to addoldChild
- the child node to replace- Returns:
- never
- Throws:
DOMException
- always- See Also:
-
removeChild
Remove a child node (always fails).- Specified by:
removeChild
in interfaceNode
- Parameters:
oldChild
- the child node to remove- Returns:
- never
- Throws:
DOMException
- always- See Also:
-
appendChild
Append a new child node (always fails).- Specified by:
appendChild
in interfaceNode
- Parameters:
newChild
- the node to add- Returns:
- never
- Throws:
DOMException
- always- See Also:
-
hasChildNodes
public boolean hasChildNodes()Test for child nodes.- Specified by:
hasChildNodes
in interfaceNode
- Returns:
- false
-
cloneNode
Create a copy of this node. -
normalize
public void normalize()Normalize the text descendants of this node.This method has no effect, since namespace nodes have no descendants.
-
isSupported
Test if a DOM2 feature is supported. (None are.)- Specified by:
isSupported
in interfaceNode
- Parameters:
feature
- the feature nameversion
- the feature version- Returns:
- false
-
getNamespaceURI
Get the namespace URI of this node.Namespace declarations are not themselves Namespace-qualified.
- Specified by:
getNamespaceURI
in interfaceNode
- Returns:
- null
-
getPrefix
Get the namespace prefix of this node.Namespace declarations are not themselves namespace-qualified.
-
setPrefix
Change the namespace prefix of this node (always fails).- Specified by:
setPrefix
in interfaceNode
- Parameters:
prefix
- the new prefix- Throws:
DOMException
- always thrown
-
getLocalName
Get the XPath name of the namespace node;; i.e. the namespace prefix.- Specified by:
getLocalName
in interfaceNode
- Returns:
- the namespace prefix
-
hasAttributes
public boolean hasAttributes()Test if this node has attributes.- Specified by:
hasAttributes
in interfaceNode
- Returns:
- false
-
disallowModification
Throw a NO_MODIFICATION_ALLOWED_ERR DOMException.- Throws:
DOMException
- always thrown
-
hashCode
public int hashCode()Generate a hash code for a namespace node. -
equals
Test for equivalence with another object.Two Namespace nodes are considered equivalent if their parents, names, and values are equal.
-
hashCode
Helper method for generating a hash code.- Parameters:
o
- the object for generating a hash code (possibly null)- Returns:
- the object's hash code, or 0 if the object is null
- See Also:
-
equals
Helper method for comparing two objects.- Parameters:
a
- the first object to compare (possibly null)b
- the second object to compare (possibly null)- Returns:
- true if the objects are equivalent or are both null
- See Also:
-
getBaseURI
Return the base URI of the document containing this node. This only works in DOM 3.- Specified by:
getBaseURI
in interfaceNode
- Returns:
- null
-
compareDocumentPosition
Compare relative position of this node to another nbode. (Always fails). This method is included solely for compatibility with the superclass.- Specified by:
compareDocumentPosition
in interfaceNode
- Parameters:
other
- the node to compare to- Returns:
- never
- Throws:
DOMException
- NOT_SUPPORTED_ERR
-
getTextContent
Return the namespace URI.- Specified by:
getTextContent
in interfaceNode
- Returns:
- the namespace URI
- See Also:
-
setTextContent
Change the value of this node (always fails). This method is included solely for compatibility with the superclass.- Specified by:
setTextContent
in interfaceNode
- Parameters:
textContent
- the new content- Throws:
DOMException
- always
-
isSameNode
Returns true if and only if this object represents the same XPath namespace node as the argument; that is, they have the same parent, the same prefix, and the same URI.- Specified by:
isSameNode
in interfaceNode
- Parameters:
other
- the node to compare to- Returns:
- true if this object represents the same XPath namespace node as other; false otherwise
-
lookupPrefix
Return the prefix bound to this namespace URI within the scope of this node.- Specified by:
lookupPrefix
in interfaceNode
- Parameters:
namespaceURI
- the URI to find a prefix binding for- Returns:
- a prefix matching this namespace URI
- Throws:
UnsupportedOperationException
- in DOM 2
-
isDefaultNamespace
Return true if the specified URI is the default namespace in scope (always fails). This method is included solely for compatibility with the superclass.- Specified by:
isDefaultNamespace
in interfaceNode
- Parameters:
namespaceURI
- the URI to check- Returns:
- never
- Throws:
UnsupportedOperationException
- always
-
lookupNamespaceURI
Return the namespace URI mapped to the specified prefix within the scope of this namespace node.- Specified by:
lookupNamespaceURI
in interfaceNode
- Parameters:
prefix
- the prefix to search for- Returns:
- the namespace URI mapped to this prefix
- Throws:
UnsupportedOperationException
- in DOM 2
-
isEqualNode
Returns true if this object binds the same prefix to the same URI. That is, this object has the same prefix and URI as the argument.- Specified by:
isEqualNode
in interfaceNode
- Parameters:
arg
- the node to compare to- Returns:
- true if this object has the same prefix and URI as the argument; false otherwise
-
getFeature
Returns the value of the requested feature. Always returns null.- Specified by:
getFeature
in interfaceNode
- Returns:
- null
-
setUserData
Associates an object with a key.- Specified by:
setUserData
in interfaceNode
- Parameters:
key
- the key by which the data will be retrieveddata
- the object to store with the keyhandler
- ignored since namespace nodes cannot be imported, cloned, or renamed- Returns:
- the value previously associated with this key; or null if there isn't any such previous value
-
getUserData
Returns the user data associated with the given key.- Specified by:
getUserData
in interfaceNode
- Parameters:
key
- the lookup key- Returns:
- the object associated with the key; or null if no such object is available
-