Home > Web Front-end > JS Tutorial > body text

JS reads XML file sample code_javascript skills

WBOY
Release: 2016-05-16 17:14:42
Original
1109 people have browsed it
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);
}
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!