【javascript】js加载xml字符串

//加载xml字符串

 function loadXmlStr(xmlStr) {
    var xmlDom,MicsoftString = ['Microsoft.XmlDom', 'MSXML2.DOMDocument', 'MSXML2.DOMDocument.3.0', 'MSXML2.DOMDocument.6.0'], i = 0;
    for (i; i < MicsoftString.length; i++)//IE8及以前版本
    {
        try {
            xmlDom = new ActiveXObject(MicsoftString[i]);
            xmlDom.loadXML(xmlStr);//load为加载xml文档
            break;
        }
        catch (ex) {
        }
    }
    if (!xmlDom)//IE9+ ff等浏览器
    {
        try {
            xmlDom = (new DOMParser()).parseFromString(xmlStr, "text/xml");
        }
        catch (ex) {
        }
    }
    return xmlDom;
}

posted @ 2014-05-20 14:36  酱油帝君  阅读(181)  评论(0编辑  收藏  举报