XML DOM lengthProperty
Comment object
Definition and Usage
The length attribute returns the length of the text in a comment node (in characters).
Syntax
commentNode.length
Example
The following code snippet usesloadXMLDoc()put "books_comment.xmlLoad into xmlDoc, and retrieve the text node data and length from the first <title> 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].length);
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].length);
document.write("
");
}
}
The above code will output:
44
Try it Yourself »
In the example above, we use a loop and an if statement to perform processing only for comment nodes. The node type of a comment node is 8.
Comment objectother extensions