XML DOM item()Methods
NamedNodeMap Object
Definition and Usage
The item() method returns the node at the specified index in the node list.
Syntax
item(index)
| Parameter | Description |
|---|---|
| index | index. |
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 above code will output:
COOKING
CHILDREN
WEB
WEB
CHILDREN
WEB
WEB
Try it Yourself »
Try it Yourself
item() - Loop through items in a node list
getNamedItem() - Change the Value of an Item
NamedNodeMap Objectother extensions