JS讀取XML文件方法兼容各大瀏覽器



  function LoadXMLFile(xmlFile) {
                var xmlDom = null;
                if (window.ActiveXObject) {
                    xmlDom = new ActiveXObject("Microsoft.XMLDOM");
                    //xmlDom.loadXML(xmlFile);//如果用的是XML字符串
                    xmlDom.load(xmlFile); //如果用的是xml文件。
                } else if (document.implementation && document.implementation.createDocument) {
                    var xmlhttp = new window.XMLHttpRequest();
                    xmlhttp.open("GET", xmlFile, false);
                    xmlhttp.send(null);
                    xmlDom = xmlhttp.responseXML.documentElement;//一定要有根節(jié)點(diǎn)(否則google瀏覽器讀取不了)
                } else {
                    xmlDom = null;
                }
                return xmlDom;
            }


原文鏈接:JS讀取XML文件方法兼容各大瀏覽器