XML DOM getNamedItem () method
Definition and Usage
getNamedItem () method returns the specified node.
grammar
getNamedItem(nodename)
参数 | 描述 |
---|---|
nodename | 要检索的节点名称。 |
Examples
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc loop through <book> element and print category attribute values:
Examples
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 + "
");
}
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
att=x.item(i).attributes.getNamedItem("category");
document.write(att.value + "
");
}
The code above will output:
COOKING
CHILDREN
WEB
WEB
CHILDREN
WEB
WEB
try it"
Try Demos
getNamedItem () - change the value of an item
NamedNodeMap objects