XML DOM nodeValue Property

Definition and Usage

The nodeValue property sets or returns the value of the node based on its type.

Syntax:

attrObject.nodeValue

Example

In all 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)