XML DOM getNamedItem() method

NamedNodeMap object reference manual

Definition and usage

The getNamedItem() method can return the specified node.

Syntax:

getNamedItem(nodename)
Parameter Description
nodename The node name to be retrieved.

Example

In all examples, we will use the XML file books.xml, and JavaScript functions loadXMLDoc().

The following code snippet can iterate over the <book> elements and output the value of the category attribute:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
  {
  var att=x.item(i).attributes.getNamedItem("category");
  document.write(att.value + "<br />")
  }

Output:

COOKING
CHILDREN
WEB
WEB

NamedNodeMap object reference manual