XML DOM data Attribute
Definition and Usage
The data attribute returns the text content of the comment.
Syntax:
commentNode.data
Example
The following code segment uses JavaScript functions loadXMLDoc() Load the XML file books_comment.xml Load xmlDoc and output the comment text content of the first <book> element:
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("<br />");
}
}
The output of the above code:
(Book 6) (Hardcover)
In this example, we use a loop and if statement to perform processing that is only for comment nodes. The node type of comment nodes is 8.