Posted in Javascript onNovember 15, 2013
//读取XML文件 function loadXML(xmlFile) { var xmlDoc; if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.load(xmlFile); } else if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.async = false; xmlDoc.load(xmlFile); } else { alert('您的浏览器不支持该系统脚本!'); } return xmlDoc; } //输出XML文件 function outXML(filename){ var xmlDoc = loadXML(filename); var x = xmlDoc.getElementsByTagName("properties"); var text=x[0].outerHTML.replace(/</g,"<"); return text; } function dirXML(xmlDoc){ var entry=xmlDoc.getElementsByTagName("properties")[0].getElementsByTagName("entry"); for (var i=0,j=entry.length; i<j;i++){ console.log(entry[i].getAttribute("key")); console.log(entry[i].childNodes[0].nodeValue); } }
JS读取XML文件示例代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@