XML DOM dataProperty
Comment object
Definition and Usage
The data attribute sets or returns the text of the comment.
Syntax
commentNode.data
Example
The following code snippet usesloadXMLDoc()put "Load into xmlDoc and output the comment text of the first <book> element:
Example
xmlDoc=loadXMLDoc("books_comment.xml");
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType==8)
{
//Process only comment nodes
document.write(x[i].data);
document.write("
");
}
}
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType==8)
{
//Process only comment nodes
document.write(x[i].data);
document.write("
");
}
}
The above code will output:
125 Simple and Delicious Recipes (Hardcover)
Try it Yourself »
In the above example, we use a loop and an if statement to perform processing only for comment nodes. The node type of comment nodes is 8.
Comment objectother extensions