NamedNodeMap object (Object/DOM)

Where nodes have a name attribute, they can be presented as members of a NamedNodeMap collection object.

Availability:

DOM level - 1
JavaScript - 1.5
JScript - 5.0
Internet Explorer - 5.0
Netscape - 6.0
Inherits from:Array
JavaScript syntax:-myNamedNodeMap = new NamedNodeMap()
Object properties:length
Object methods:getNamedItem(), item(), removeNamedItem(), setNamedItem()

A NamedNodeMap is a collection of nodes that can be accessed by name. It does not inherit from NodeList, and DOM does not mandate any parentage. It will probably inherit from Collection or Array but this appears to be implementation dependant. A general purpose Dictionary class would be helpful as a starting point but these are not available in all implementations.

The nodes are not collated in any particular order and you can access them with a numeric index as well as by associative name.

This implies a namespacing issue and clearly there may be problems with your document if nodes share the same name and need to be collected into a NamedNodeList entity.

The DOM level 2 specification provides these new methods to cope with namespaces:

DOM 2 standardization is not quite stable and no browsers support it yet. At this time, browsers have reached DOM level 1 capabilities and we can expect support for these namespace extensions in the next round of browser upgrades.

See also:Collection object, DOM, DOM - Level 1, Node object, Node.attributes[], NodeList object

PropertyJavaScriptJScriptN IEOperaNESECMADOMCSSHTMLNotes
length1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/a-

MethodJavaScriptJScriptN IEOperaNESECMADOMCSSHTMLNotes
getNamedItem()1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/a-
item()1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/aWarning
removeNamedItem()1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/a-
setNamedItem()1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/a-

Web-references:

http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1074577549