1

So I'm passing XML to a PHP file. Things work great in non-IE browsers, and things work great in IE8 and IE11, but not in 9 and 10.

The culprit, I'm betting, is that first "if" condition in the stringIt function below. What I don't know is why exactly it works for 8 and 11 but not 9 and 10, and more importantly, what should I be doing instead to deal with all four versions.

Any help is greatly appreciated.

function stringIt($xml) {
    var doc = $xml[0],
        string;
    if(window.ActiveXObject) { alert('activeX'); string = doc.xml; }
    else { string = (new XMLSerializer()).serializeToString(doc); }
    return string;
}

EDIT : Here's the solution I ended up using. Thanks again for that link tjb.

function stringIt($xml) {
    var doc = $xml[0],
        string;
    if(window.ActiveXObject) { alert('activeX'); string = doc.xml; }
    else { string = (new XMLSerializer()).serializeToString(doc); }
    if(string == null) {string = (new XMLSerializer()).serializeToString(doc);}
    return string;
}
Frankenscarf
  • 1,189
  • 7
  • 10

1 Answers1

0

You might try some variation of this:

$('<div>').append($xml).html();

(taken from https://stackoverflow.com/a/15885505/762844)

It does mess up casing, though, so <MyNode ...> apparently becomes <mynode>.

Community
  • 1
  • 1
tjb1982
  • 2,257
  • 2
  • 26
  • 39
  • Thanks tjb. After reading several posts related to the one you linked, I ended up just testing the string after the first if/else in stringIt and if it's null then serialize. Appears to work for all 4 versions. – Frankenscarf May 17 '14 at 08:03