-1

I have data coming in XML file, and initially i was using jQuery Ajax function to read and process data in XML file... whole functionality works perfectly until i have tried on IE 9 browser and have so many different solution but is just not read data through XML file.I am using data type ($.browser.msie) ? "text" and xml for rest of browser, followed by i am calling parseXml() for IE but is just not happening .... I am really struggling and thinking to change other possible method that is suitable for all!!!

 function testXml() {

    $.ajax({
        type: 'GET',
        url: 'XML_estatesIT_op4.xml',
        dataType: ($.browser.msie) ? "text" : "xml",
        success: function (xml) {

            theXml = parseXml(xml);

            $(theXml).find("property").each(function () {

                var b1 = $(this).find('proptype').text();

                alert(b1);                        
            });
        },
        error: function () {
            alert("An error occurred while processing XML file.");
        }
     });
 }

 function parseXml(xml) {

    if (jQuery.browser.msie) {
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        xmlDoc.loadXML(xml);
        xml = xmlDoc;
    }

    return xml;
}

I am wondering if i can read

  1. xml data in ajax function
  2. if it success, convert xmlDocument object into JSON
  3. then process on data, so that i can read in IE and other browsers...

I havn't use JSON, can anyone please guide me if i can do that!!

many thanks

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99
K.Z
  • 5,201
  • 25
  • 104
  • 240

1 Answers1

0

finally I have found the solution, the trick is use separate code XML for IE browsers that are version of less than 10 .

so every time Ajax is call a method parseXml is called with input parameter XML Dom or text, depending on browser .... and if current browser is IE, it upload XML doc, process it according to Microsoft standards and return XML and rest of processes in Ajax carries on as expected!!

note : browser.msie is not supported in jQuery 1.9 but you can add jquery-migrate-1.2.1.min.js in order to make it compatible or use userAgent and find which is current browser

  $.ajax({
      type: 'GET',
      url: 'XML_file.xml',
      dataType: ($.browser.msie) ? "text" : "xml",
      success: function (xml) {

         var processedXML = parseXml(xml);

         $(processedXML).find('my record').each(function () {  //code  } 
  });


  function parseXml(xml) {

  if ($.browser.msie)  {

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

        xmlhttp.open("GET", "XML_file.xml", false);
        xmlhttp.send();
        xmlDoc = xmlhttp.responseXML;

        xml = xmlDoc;
  }
  return xml;
}

my original issue answered here and i have asked if i can convert xml to json, yes you can; once the success method is called ... xml document came down and you can use xml-t0-json plugin to do that...

K.Z
  • 5,201
  • 25
  • 104
  • 240