Not able to load xml file in IE8

折月煮酒 提交于 2019-12-12 04:49:43

问题


I'm trying to find the solution to load xml file and retrieve element value by tag name but stuck at the final step. Code is working in all other modern browsers except IE8.

function getXML(xmlStr) {
    if (window.DOMParser) {
       alert("window.DOMParser");
       return (new window.DOMParser()).parseFromString(xmlStr, "text/xml");
    } else if (typeof window.ActiveXObject != "undefined" && new window.ActiveXObject("Microsoft.XMLDOM")) {
       alert("Microsoft.XMLDOM");
       var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = "false";
       xmlDoc.loadXML(xmlStr);
       alert("xmlDoc");
       return xmlDoc;
    } else {
       return null;
  }
}

$(document).ready(function() {
  var xmlStr = "<xml><elem>element1</elem><elem>element2</elem></xml>";
  var xmlDoc = getXML(xmlStr);
  $("#result").html("<b>Elemtent:</b> " + JSON.stringify(xmlDoc) + "<br/><br>");
});

I've created jsfiddle here which is the modification of the actual post answer by Tim Down.

I've tried many ways but no luck at all. Is it possible to load xml and get values in IE8?

来源:https://stackoverflow.com/questions/44895014/not-able-to-load-xml-file-in-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!