dimanche 7 février 2016

get and parsing xml using ajax on IE

i have the following xml returned from a url:

    <?xml version='1.0' encoding='UTF-8' ?>
<!--  search hits from ThunderBallWebService -->
<iHS>
  <Params>
    <param name='start'><![CDATA[0]]></param>
    <param name='return'><![CDATA[content_arabic;url;metatag.publishdt;metatag.title;metatag.site;metatag.channel;metatag.image;metatag.newImage;metatag.newstopics]]></param>
    <param name='groupby'><![CDATA[metatag.site]]></param>
    <param name='output'><![CDATA[xml]]></param>
    <param name='hitsPerPage'><![CDATA[12]]></param>
    <param name='all'><![CDATA[مصر]]></param>
    <param name='filter'><![CDATA[-id:*learning.aljazeera*]]></param>
  </Params>
  <Response>
    <Qtime>16</Qtime>
  </Response>
  <HitsCount>
    <hitsPerPage>12</hitsPerPage>
    <total>1</total>
    <matches>7</matches>
    <start>0</start>
    <end>1</end>
    <totalIsExact>true</totalIsExact>
  </HitsCount>
  <Results>
    <group id='0' name='metatag.site' value='57258a24e91a42b0b2399dccf49cf8c1' count='7' start='0'>
      <Hits>
        <Hit id='0'>
          <metatag.publishdt type=''><![CDATA[2015-11-02]]></metatag.publishdt>
          <metatag.image type=''><![CDATA[65cb6546-b449-4c72-b0c0-eeb07d9adfb1]]></metatag.image>
          <metatag.title type=''><![CDATA[انطلاق انتخابات <em>مصر</em> بالداخل والمعارضة تقاطع]]></metatag.title>
          <id type=''><![CDATA[http://ift.tt/1TM4Z3J;
          <url type=''><![CDATA[http://ift.tt/1W1vHnz;
          <content_arabic type=''><![CDATA[انطلاق انتخابات <em>مصر</em> بالداخل والمعارضة تقاطع تنطلق اليوم الأحد المرحلة الأولى من الانتخابات]]></content_arabic>
          <metatag.site type=''><![CDATA[57258A24E91A42B0B2399DCCF49CF8C1]]></metatag.site>
          <metatag.newstopics type=''><![CDATA[42c25b5e-f336-47c0-a1f8-d17deec868d7,]]></metatag.newstopics>
          <metatag.channel type=''><![CDATA[84AD340701C24F699597D698D2547472]]></metatag.channel>
        </Hit>
        <Hit id='1'>
          <metatag.publishdt type=''><![CDATA[2015-10-19]]></metatag.publishdt>
          <metatag.image type=''><![CDATA[e5762dbc-705d-43d2-920e-9cbb89e5a850]]></metatag.image>
          <metatag.title type=''><![CDATA[كوميديا الدعاية الانتخابية بمصر]]></metatag.title>
          <id type=''><![CDATA[http://ift.tt/1TM4Z3L;
          <url type=''><![CDATA[http://ift.tt/1W1vFML;
          <content_arabic type=''><![CDATA[كوميديا الدعاية الانتخابية بمصر تبدو مشاهد الدعاية الانتخابية لمرشحى برلمان <em>مصر</em>، كما لو كانت مقتطعة]]></content_arabic>
          <metatag.site type=''><![CDATA[57258A24E91A42B0B2399DCCF49CF8C1]]></metatag.site>
          <metatag.newstopics type=''><![CDATA[33a9ad72-a45f-4827-bb18-2e71685abf89,e8b8f3f7-4fd6-4d78-846d-9c8d2239fda4,]]></metatag.newstopics>
          <metatag.channel type=''><![CDATA[84AD340701C24F699597D698D2547472]]></metatag.channel>
        </Hit>
        <Hit id='2'>
          <metatag.publishdt type=''><![CDATA[2015-11-18]]></metatag.publishdt>
          <metatag.image type=''><![CDATA[246d383c-bb2a-4167-b75f-0bf8c68b0ca8]]></metatag.image>
          <metatag.title type=''><![CDATA[إندبندنت: فيديو منسوب لتنظيم الدولة يهدد إسرائيل]]></metatag.title>
          <id type=''><![CDATA[http://ift.tt/1W1vHnG;
          <url type=''><![CDATA[http://ift.tt/1W1vG2Z;
          <content_arabic type=''><![CDATA[ الجهات، من جانب شبه جزيرة سيناء في <em>مصر</em> ومن جانب دمشق في سوريا ومن جهات أخرى. تهديد مباشر وأضافت الصحيفة]]></content_arabic>
          <metatag.site type=''><![CDATA[57258A24E91A42B0B2399DCCF49CF8C1]]></metatag.site>
          <metatag.newstopics type=''><![CDATA[42c25b5e-f336-47c0-a1f8-d17deec868d7,]]></metatag.newstopics>
          <metatag.channel type=''><![CDATA[84AD340701C24F699597D698D2547472]]></metatag.channel>
        </Hit>
      </Hits>
    </group>
  </Results>
  <Faceted>
    <field name='metatag.site'>
      <value name='57258a24e91a42b0b2399dccf49cf8c1' count='7'>57258a24e91a42b0b2399dccf49cf8c1 (7)</value>
      <value name='null' count='0'>null (0)</value>
    </field>
  </Faceted>
</iHS>

when i try to parse it in chrome and firefox, everything works like a charm, but in ie i'm getting the following error:

XML5632: Only one root element is allowed. Line: 2, Column 1

here is my ajax :

    function ajxGetXml(url) {
    debugger;
    $.ajax({
        crossDomain: true,
        type: "GET",
        cache: true,
        url: url,// decodeURI(url), //encodeURI(url),
        dataType: "xml",
        success: parseXml,
        timeout: 10000,        // sets timeout for the request (10 seconds)
        error: function (req, err) { console.log('my message' + err); }
    });
}

and the function to parse the xml :

    function parseXml(xObj) {
    debugger;
    var dom = null;
    if (window.DOMParser) {
        try {
            dom = (new DOMParser()).parseFromString(xObj, "text/xml");
        }
        catch (e) { dom = null; }
    }
    else if (window.ActiveXObject) {
        try {
            dom = new ActiveXObject('Microsoft.XMLDOM');
            dom.async = false;
            if (!dom.loadXML(xObj)) // parse error ..
                window.alert(dom.parseError.reason + dom.parseError.srcText);
        }
        catch (e) { dom = null; }
    }
}

i'm stuck here for 4 days with no luck, any help will be appreciated. Thanks!




Aucun commentaire:

Enregistrer un commentaire