XML DOM getAttributeNode () method
Definition and Usage
getAttributeNode () method to obtain an attribute node by name from the current element.
grammar
elementNode.getAttributeNode(name)
参数 | 描述 |
---|---|
name | 必需。规定要获取的属性节点。 |
Examples
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and achieved "category" attribute from all <book> element:
Examples
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
attnode=x.item(i).getAttributeNode("category");
document.write(attnode.name);
document.write(" = ");
document.write(attnode.value);
document.write("
");
}
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
attnode=x.item(i).getAttributeNode("category");
document.write(attnode.name);
document.write(" = ");
document.write(attnode.value);
document.write("
");
}
Output:
category = COOKING
category = CHILDREN
category = WEB
category = WEB
category = CHILDREN
category = WEB
category = WEB
try it"
Element object