2

I have a huge page with really lots of data. Sometimes I need to reload this data using Ajax, so ajax request:

if (window.XMLHttpRequest) {
    this._request = new XMLHttpRequest();
  } else {
    this._request = new ActiveXObject("Microsoft.XMLHTTP");

Then, I access this data with request.responseXML. I faced a problem, when size of responsibility more than 800k characters. IE doesnt generate responseXML, its just empty XMLObject, but in responseText everithing is OK. I`ve tried to parse XML using the following code:

  if (request.responseXML) {
    var responseXML = request.responseXML;

    //TODO: for huge xml responses some versions of IE can't automaticly parse XML
    if (O$.isExplorer && responseXML && !responseXML.firstChild) {
      var originalResponseText = request.responseText;

      if (window.DOMParser) {
        var parser = new DOMParser();
        responseXML = parser.parseFromString(originalResponseText, 'text/xml');
      } else {            
        responseXML = new ActiveXObject("Microsoft.XMLDOM");
        responseXML.async = false;
        responseXML.loadXML(originalResponseText);
      }
    }

But I faced the same problem. Then, I tried to parse XML using jQuery:

responseXML = jQuery.parseXml(request.responseXML);

But the problem is still the same, everything is fine when the response length small, but for huge response I still get empty XML object with the parse error inside.

errorCode : -2147467259

filepos : 814853

reason : “Unspecified error\r\n”;

I check those position inside response string and everything is correct, just some ordinal symbol. Also I’ve recheck XML lots of time and I am sure that it’s valid. I don’t know what to do at all.

Also I tried to write my own xml parser, but I think that this is problem has more simple solution.

Thanks in Advance.

Aventes
  • 569
  • 1
  • 8
  • 20

1 Answers1

1

It would seem that IE notoriously has difficulties parsing XML data, and there may not be that much you can really do about it. A work around is that you can try to parse the XML data with IE, and if it fails, construct a new parser that will construct XML data out of the plaintext (which as you mentioned will work seemingly regardless of size). Take a look at the similar problem and answer here. It boils down to (pseudocode)

function() {
    var XMLdata = reponse.XMLdata;

    If (XMLdata.error) {
        var parser = construct new DOMParser;
        XMLdata = parser.XMLparse(response.plaintext);
    }

    return XMLdata;
}
Community
  • 1
  • 1
UnstableEagle
  • 562
  • 2
  • 16