XML DOM item() Method
Complete NamedNodeMap Object Reference
Definition and Usage
The item() method returns the node at the specified index in a node list.
Syntax
Parameter |
Description |
index |
The index |
Example
The following code fragment loads "books.xml"
into xmlDoc using
loadXMLDoc(), loops through the <book> elements and prints the
values of the category attributes:
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 output of the code above will be:
Try-It-Yourself Demos
item() -
Loop through the items in a node list
getNamedItem() - Get an item's value
getNamedItem() - Change an item's value
Complete NamedNodeMap Object Reference
Learn XML with <oXygen/> XML Editor - Free Trial!
|
|
oXygen helps you learn to define,
edit, validate and transform XML documents. Supported technologies include XML Schema,
DTD, Relax NG, XSLT, XPath, XQuery, CSS.
Understand in no time how XSLT and XQuery work by using the intuitive oXygen debugger!
Do you have any XML related questions? Get free answers from the oXygen
XML forum
and from the video
demonstrations.
Download a FREE 30-day trial today!
|
|