XML DOM Comment Node length 属性

XML DOM – Comment 对象

定义和用法

length 属性返回注释节点中文本的长度(以字符计)。

语法

commentNode.length


实例

下面的代码片段使用 loadXMLDoc() 把 "books_comment.xml" 载入 xmlDoc 中,并从第一个 <title> 元素取得文本节点数据和长度:

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>");
  } 
}

在上面的实例中,我们使用一段循环和 if 语句来执行只针对 comment 节点的处理。comment 节点的节点类型是 8。

XML DOM – Comment 对象