获得兼容的xmlDocument

来源:互联网 发布:汪苏泷 知乎 编辑:程序博客网 时间:2024/05/23 15:06

//定义一个函数getXmlDocument();

function getXMLDocument(){

var xDocument=null;

if(document.implementation && document.implementation.createDocument(){

 xDocument=document.implementation.createDocument(" "," ",null);//Mozilla

}else if (typeof ActiveXOBject  !="undefined"){

   var maXmlAx==null;

   try{

    msXmlAx=new ActiveXObject("Msxml2.DOMDocument");//newIE

    }catch(e){

     msXmlAx=new ActiveXObject("Msxml.DOMDocument");//oldIE

      }

      xDocument=msXmlAx;

    }

   if(xDocument==null || typeof xDocument.load=="undefined") {

     xDocument=null;

    }

   return xDocument;

}