XML DOM item() Method
Definition and Usage
The item() method can return the node in the node list at the specified index number.
Syntax:
item(index)
Parameter | Description |
---|---|
index | Index Number |
Example
In all examples, we will use the XML file books.xml, and the JavaScript function loadXMLDoc().
The following code snippet can loop through the <book> element 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