JQuery XML Parsing IE7 / IE8

I am trying to access XML content attached to the end of an HTML document (generated material) using jquery using this method:

$("SELECTION_STATE").find("CHARACTERISTIC").each( function() {
     if($(this).attr("name") == "Z_MDST" ) {
         alert($(this).find("MEMBER").attr("name"));
     }
 });

this works fine in Firefox and Chrome, but not in IE, it won’t warn anything.

this is the xml I'm trying to execute

<SELECTION_STATE>

    <SELECTION type="CARTESIAN_PRODUCT">
      <CHARACTERISTICS>
        <CHARACTERISTIC name="Z_MDST">
          <SELECTIONS>
            <SELECTION type="SINGLE_MEMBER">
              <MEMBER name="00002213" type="MEMBER" text="2213"/>
            </SELECTION>
          </SELECTIONS>
        </CHARACTERISTIC>

Is there a way I can achieve this with jquery 1.5?

Thanks in advance

+5
source share
2 answers

Because you are in an HTML document. IE will not recognize XML.

console.log($("SELECTION_STATE").get());

returns an HTMLUnknownElement object in IE

To use XML, you will have to run it through the IE XML parser. Sort of.

var x = new ActiveXObject("Microsoft.XMLDOM");
x.loadXML(yourXML) 

, , , ($. browser.msie)

: XML AJAX?

:

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
var myXML = document.body.innerHTML;  // or wherever you are storing the XML in the DOM
xmlDoc.loadXML(myXML)

if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   console.log("You have error " + myErr.reason);
} else {
   console.log(xmlDoc.xml);
}

$("SELECTION_STATE", xmlDoc).find("CHARACTERISTIC").each( function() {
     if($(this).attr("name") == "Z_MDST" ) {
         alert($(this).find("MEMBER").attr("name"));
     }
});
+6

jQuery, parseXML (http://api.jquery.com/jQuery.parseXML/, 1.5).

var xmlDoc = $.parseXML(data);

$(xmlDoc).find("CHARACTERISTIC").each( function() {
    if($(this).attr("name") == "Z_MDST" ) {
        alert($(this).find("MEMBER").attr("name"));
    }
});
+6

All Articles