首頁  >  文章  >  web前端  >  JS讀取XML檔案範例程式碼_javascript技巧

JS讀取XML檔案範例程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:14:421110瀏覽
複製程式碼 程式碼如下:

//讀取XML檔
function loadXML(xml) {loadXML
var xmlDoc;
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load(xmlFileDoc.async = false;
xmlDoc.load(xmlFile);
}
else if (document.implementation && document.implementation.createDocument) {
xmlDoc = document.implementation.createDocument("", "", null);

xmlDoc.load(xmlFile);
} else {
alert('您的瀏覽器不支援該系統腳本!');
}
return xmlDoc;
}

//輸出XML檔案
function outXML(filename){
var xmlDoc = loadXML(filename);
var x = xmlDoc.getElementsByTagName("properties"); =x[0].outerHTML.replace(/,"return text;
}

function dirXML(xmlDoc){
var entry=xmlDoc. getElementsByTagName("properties")[0].getElementsByTagName("entry");
for (var i=0,j=entry.length; iconsole.log(entry[i ].getAttribute("key"));
console.log(entry[i].childNodes[0].nodeValue);
}
}
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn