Home  >  Article  >  Web Front-end  >  JS reads XML file sample code_javascript skills

JS reads XML file sample code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:14:421144browse
Copy code The code is as follows:

//Read XML file
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('Your browser does not support this system script!');
}
return xmlDoc;
}

//Output XML file
function outXML(filename){
var xmlDoc = loadXML(filename);
var x = xmlDoc.getElementsByTagName("properties");
var text =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);
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn