注:判断是否是ie浏览器和非ie浏览器的方法有多种,在此只介绍用例中的方法:


1、解析xml字符串,得到xml对象的方式:

function createXml(str){
  if(document.all){//IE浏览器
      var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
      xmlDoc.loadXML(str);
      return xmlDoc;
  }
  else{//非IE浏览器
          return new DOMParser().parseFromString(str, "text/xml");
    }
}


2、解析xml文件,将其转换为xml对象的方式:

/**
* aXMLFileName是xml文件路径名
*/
function getXmlDoc(){
    try{
      if (window.ActiveXObject){
        xmlDoc= new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        isLoaded = xmlDoc.load(aXMLFileName);
      }
      else if(document.implementation&& document.implementation.createDocument){
        try{
            xmlDoc = document.implementation.createDocument('', '', null);
            xmlDoc.async = false;
            xmlDoc.load(aXMLFileName);
        } catch(e){
            var xmlhttp = new window.XMLHttpRequest();
            xmlhttp.open("GET",aXMLFileName,false); 
            xmlhttp.send(null);
            xmlDoc = xmlhttp.responseXML;
        }
      }
      else{
          alert("load data error");
      }
    }
    catch(e){  
        alert(e.message);
    }
}