Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 1116
نمايش فراداده

NamedNodeMaporg.w3c.dom

Java 1.4

The NamedNodeMap interface defines a collection of nodes that may be looked up by name or by namespace URI and local name. It is unrelated to the java.util.Map interface. Use getNamedItem( ) to look for and return a node whose getNodeName( ) method returns the specified value. Use getNamedItemNS( ) to look for and return a node whose getNamespaceURI( ) and getLocalName( ) methods return the specified values. A NamedNodeMap is a mapping from names to nodes, and does not order the nodes in any particular way. Nevertheless, it does impose an arbitrary ordering on the nodes and allow them to be looked up by index. Use getLength( ) to find out how many nodes are contained in the NamedNodeMap, and use item( ) to obtain the Node object at a specified index.

If a NamedNodeMap is not read-only, you can use removeNamedItem( ) and removeNamedItemNS( ) to remove a named node from the map, and you can use setNamedItem( ) and setNamedItemNS( ) to add a node to the map, mapping to it from its name or its namespace URI and local name.

NamedNodeMap objects are "live," which means that they immediately reflect any changes to the document tree. For example, if you obtain a NamedNodeMap that represents the attributes of an element, and then add a new attribute to that element, the new attribute is automatically available through the NamedNodeMap: you do not need to obtain a new NamedNodeMap to get the modified set of attributes.

NamedNodeMap is returned only by relatively obscure methods of the DOM API. The most notable use is as the return value of the getAttributes( ) method of Node. It is usually easier to work with attributes through the methods of the Element interface, however. Two methods of DocumentType also return read-only NamedNodeMap objects.

public interface

NamedNodeMap { // Public Instance Methods int

getLength ( ); Node

getNamedItem (String

name ); Node

getNamedItemNS (String

namespaceURI , String

localName ) throws DOMException; Node

item (int

index ); Node

removeNamedItem (String

name ) throws DOMException; Node

removeNamedItemNS (String

namespaceURI , String

localName ) throws DOMException; Node

setNamedItem (Node

arg ) throws DOMException; Node

setNamedItemNS (Node

arg ) throws DOMException; }

Returned By

DocumentType.{getEntities( ), getNotations( )}, Node.getAttributes( )