XML DOM data 屬性

定義和用法
data 屬性設置或返回注釋的文本。
語法
commentNode.data
實例
下麵的代碼片段使用 loadXMLDoc() 把 "books_comment.xml" 載入 xmlDoc 中,並輸出第一個 <book> 元素的注釋文本:
實例
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("
");
}
}
上面的代碼將輸出:
125 Simple and Delicious Recipes (Hardcover)
在上面的實例中,我們使用一段迴圈和 if 語句來執行只針對 comment 節點的處理。comment 節點的節點類型是 8。
