XML DOM name attribute
Definition and usage
The name attribute returns the name of the attribute.
Syntax:
attrObject.name
Instance
In all examples, we will use the XML file books.xml, and the JavaScript function loadXMLDoc().
The following code snippet shows the name and value of the category attribute:
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
var x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
document.write(x.item(i).attributes[0].name
);
document.write(" = ");
document.write(x.item(i).attributes[0].value);
document.write("<br />");
}
The output of the above code is:
category = children category = cooking category = web category = web