XML DOM nodeType attribute
Definition and Usage
The nodeType property returns the type of the node.
Syntax:
attrObject.nodeType
Instance
In all the examples, we will use XML files books.xmlas well as JavaScript functions loadXMLDoc().
The following code snippet displays 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)