ویژگی داده XML DOM
تعریف و استفاده
data
ویژگی باز میگردد به دادههای انتخاب شده.
جملة
CDATANode.data
مثال
下面的代码将 "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"); برای (i = 0; i < x.length; i++) { txt += x[i].childNodes[0].data + "<br>"; } document.getElementById("demo").innerHTML = txt; }