JS - 读取XML文件
1 function loadXmlFile( xmlFile ){
2 var xmlDom = null;
3 if (window.ActiveXObject){
4 xmlDom = new ActiveXObject("Microsoft.XMLDOM");
5 //xmlDom.loadXML(xmlFile);//如果用的是XML字符串
6 xmlDom.load(xmlFile);//如果用的是xml文件。
7 }else if (document.implementation && document.implementation.createDocument){
8 var xmlhttp = new window.XMLHttpRequest();
9 xmlhttp.open("GET", xmlFile, false);
10 xmlhttp.send(null);
11 xmlDom = xmlhttp.responseXML;
12 } else {
13 xmlDom = null;
14 }
15 return xmlDom;
16 }
2 var xmlDom = null;
3 if (window.ActiveXObject){
4 xmlDom = new ActiveXObject("Microsoft.XMLDOM");
5 //xmlDom.loadXML(xmlFile);//如果用的是XML字符串
6 xmlDom.load(xmlFile);//如果用的是xml文件。
7 }else if (document.implementation && document.implementation.createDocument){
8 var xmlhttp = new window.XMLHttpRequest();
9 xmlhttp.open("GET", xmlFile, false);
10 xmlhttp.send(null);
11 xmlDom = xmlhttp.responseXML;
12 } else {
13 xmlDom = null;
14 }
15 return xmlDom;
16 }
兼容IE,FF,Chrome