XML DOM cdata data Property
❮ CDATA 对象
示例
下面的代码片段将 "books_cdata.xml" 加载到 xmlDoc 中,并获取所有 <html> 元素的数据
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books_cdata.xml", true);
xhttp.send();
function myFunction(xml) {
var x, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName("html");
for (i = 0; i < x.length; i++) {
txt += x[i].childNodes[0].data + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
上面代码的输出将是
自己动手试一试 »定义和用法
data 属性返回选定节点的数据
语法
CDATANode.data
❮ CDATA 对象