js解析xml (ie + ff + chrome + opera)

来源:互联网 发布:邯郸网络机柜 编辑:程序博客网 时间:2024/06/03 23:59
//dname:xml路径function loadXML(dname) {    var xmlDoc;      if (window.ActiveXObject) {          xmlDoc = new ActiveXObject('Microsoft.XMLDOM');          xmlDoc.async = false;          xmlDoc.load(dname);      } else if (document.implementation && document.implementation.createDocument) {          try{              xmlDoc = document.implementation.createDocument('', '', null);              xmlDoc.async = false;              xmlDoc.load(dname);          } catch(e){              var xmlhttp = new window.XMLHttpRequest();              xmlhttp.open("GET",dname,false);              xmlhttp.send(null);              xmlDoc = xmlhttp.responseXML.documentElement;          }      } else {          return null;      }          return xmlDoc;  }

有些浏览器不允许加载本地的xml文件,所有要在项目中使用。正规格式的xml文件,是木问题的。have fun!~


原创粉丝点击