不同浏览器对XML的解析是不同的(如何查看xml文件的编码格式)硬核推荐

随心笔谈1年前 (2023)发布 admin
115 0

var xmlDoc=null, xmlhttp=null;

function loadXML() {

xmlhttp=window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject(“Microsoft.XMLHttp”);

if (xmlhttp==null) {

alert(“你的浏览器不支持 XMLHttpRequest”);

return;

}

xmlhttp.open(“GET”, “1.xml?” + Date.parse(new Date()), true);

xmlhttp.setRequestHeader(“Content-Type”, “text/xml”);

xmlhttp.onreadystatechange=getmessage;

xmlhttp.send(null);

}

function getmessage() {

if (xmlhttp.readyState==4 && xmlhttp.status==200) {

xmlDoc=xmlhttp.responseXML.documentElement;

if (xmlDoc==null) {

alert(“返回的数据不正确。”);

return;

}

var nodes=xmlDoc.getElementsByTagName(“t1”)

tb=document.getElementById(“table_note”);

tbody=document.createElement(“tbody”)

for (i=0; i < nodes.length; i++) {

tr=document.createElement(“tr”)

td=document.createElement(“td”)

td.innerHTML=nodes[i].getElementsByTagName(“title”)[0].childNodes[0].nodeValue

tr.appendChild(td)

td=document.createElement(“td”)

url=nodes[i].getElementsByTagName(“url”)[0].childNodes[0].nodeValue;

td.innerHTML=”” + url + “

tr.appendChild(td)

tbody.appendChild(tr)

}

tb.appendChild(tbody)

}

}

姓名

网址

© 版权声明

相关文章