XML DOM createCDATASection() 方法

定義和用法
createCDATASection() 方法創建 CDATA 區段節點。
該方法返回 CDATASection 對象。
語法
createCDATASection(data)
參數 | 描述 |
---|---|
data | 字串,這個字串為節點規定數據。 |
實例
下麵的代碼片段使用 loadXMLDoc() 把 "books.xml" 載入 xmlDoc 中,並把 CDATA 區段節點添加到 <book> 元素:
實例
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("book");
newtext="Special Offer & Book Sale";
for (i=0;i<x.length;i++)
{
newCDATA=xmlDoc.createCDATASection(newtext);
x[i].appendChild(newCDATA);
}
for (i=0;i<x.length;i++)
{
document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
document.write(" - ");
document.write(x[i].lastChild.nodeValue);
document.write("<br>");
}
