XML DOM getNamedItem()Methods
NamedNodeMap Object
Definition and Usage
The getNamedItem() method returns the specified node.
Syntax
getNamedItem(nodename)
| Parameter | Description |
|---|---|
| nodename | The name of the node to retrieve. |
Example
The following code snippet usesloadXMLDoc()put "books.xml"Load into xmlDoc, loop through the <book> elements and print the value of the category attribute:
Example
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
att=x.item(i).attributes.getNamedItem("category");
document.write(att.value + "<br>");
}
The code above will output:
COOKING
CHILDREN
WEB
WEB
CHILDREN
WEB
WEB
Try it Yourself »
Try Demos
getNamedItem() - Change the Value of an Item
NamedNodeMap Objectother extensions