XML DOM length property
Definition and usage
The length property returns the text length of the comment node in characters.
Syntax:
commentNode.length
Example
The following code segment uses JavaScript functions loadXMLDoc() Put XML file books_comment.xml Load xmlDoc and get the length of the annotation text 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].length
;
document.write("<br />");
}
}
The output of the above code:
20
In this example, we use a loop and if statement to perform processing that is only for comment nodes. The node type of the comment node is 8.