var parseXml = { createXmlParser: function () { //IE创建此解析对象 var versions = [ ‘MSXML2.DOMDocument.6.0‘, ‘MSXML2.DOMDocument.3.0‘, ‘MSXML2.DOMDocument‘ ]; var xmlParse = null; for (var i = 0, length = versions.length; i < length; i++) { try { xmlParse = new ActiveXObject(versions[i]); if (xmlParse) { break; } } catch (error) { } } return xmlParse; }, loadXml: function (xml) { if (typeof DOMParser != ‘undefined‘) { //非IE return (new DOMParser()).parseFromString(xml, ‘text/xml‘); } else if (this.createXmlParse()) { //IE下 return this.createXmlParse().loadXML(xml); } else { throw new Error(‘no xml finded‘); } }//加载xml文件为DOM文件 };
时间: 2024-10-17 12:37:02