XML DOM nodeName Property
Definition and Usage
The nodeName property returns the name of the node based on its type.
Syntax:
attrObject.nodeName
Example
In all the examples, we will use XML files books.xmland the JavaScript function loadXMLDoc().
The following code snippet shows the node name, node value, and node type 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].nodeName
);
document.write(" = ");
document.write(x.item(i).attributes[0].nodeValue);
document.write(" (nodetype: ");
document.write(x.item(i).attributes[0].nodeType + ")");
document.write("<br />");
}
The output of the above code is:
category = children (nodetype: 2) category = cooking (nodetype: 2) category = web (nodetype: 2) category = web (nodetype: 2)