javascript跨浏览器创建XML对象

来源:互联网 发布:ds file windows 编辑:程序博客网 时间:2024/05/23 13:11

var xmlDoc = null;

function parseXML(xmlUrl)

{

  try {

    //IE

    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

    xmlDoc.async = false;

    xmlDoc.load(xmlUrl);

  }catch(e)

  {

    try{

    //FirefoxMozillaOperaetc.

    xmlDoc = document.implementation.createDocument("","",null);

    xmlDoc.async = false;

    xmlDoc.load(xmlUrl);

    }catch(e)

    {

      try{

        //google,Safari

        var xmlhttp = new window.XMLHttpRequest();

        xmlhttp.open("GET",xmlUrl,false);

        xmlhttp.send(null);

        xmlDoc = xmlhttp.responseXML.documentElement;

      }catch(e){alert(e.message+"  EROR");return;}

    }

  }

}

原创粉丝点击