TwelvestoneFront End

jquery XML DOM fix for IE 6


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
persist
 
2009-12-21

I couldn't find an answer to this problem on the web that worked. This is working so far.

jquery.find() doesn't work in IE 6,7.

You can force jquery to recognize XML from the server in IE by setting the content mime type from the server, and you'll be fine.

However, I have XML being echoed onto the page at page load. So the xml string was coming from another Javascript object, not the server. I needed something that worked client side.

The trick to get jquery to apply its own methods to XML in IE is to type cast the ie activeXObject XML with $(). Then it will be extended is a jquery accessible object.

There are still differences in the nodes traversable by browser native xml methods. But anyways this is way better than nothing. The alternative to this solution is using a completely branched method set to parse the XML in IE 6 using traditional child/parent syntax.

Add this:

parseXML = function(str){ if(!$.support.htmlSerialize){ var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(str); return $(xmlDoc); //<--- fix. jquery says, this is a dom, and treats it as one }else{ return $(str); <-- jquery says, i have a string that is xml to convert to a dom, and treats it as one } }

example use:

serializer.prototype.serializeData= function(xml){ this.data = parseXML(xml);

var Nodes = this.data.find("data");

}

People i have talked to about this fix complain that jquery should handle this, and that might be true but that you can fix it with jquery without messy source code additions shows the robustness of the jquery library. You can add this with the jquery extend method to make it available off of $.

That's all, hope this saves someone some headache.

persist
 
2010-01-12

jquery was throwing stack limits with very large XML strings (4 megabytes) when simply parsed as $(xmlstring). Firefox halted. Safari and Chrome were simply crashing. IE was working fine because I was already bypassing jquery as described in the post above. and yeah 4 megs is large for the client, but not out of the ordinary for localized apps.

I do not know what affects the function below may have on jquery chaining, but you can use classic dom parent child traversing to access your XML.

This looks for IE or sarissa and takes over the xml parsing. If it finds neither it defaults back to jquery to handle the parse. So this should work in IE 6+, firefox, safari, chrome, opera.

This can handle very large xml files:

(function($) { $.parseXML = function(str){ var dom = str; if(this.browser.msie){ dom=new ActiveXObject("Microsoft.XMLDOM"); dom.async="false"; dom.loadXML(str);

    }else if(typeof (DOMParser)!="undefined") {
        var parser=new DOMParser();
        dom=parser.parseFromString(str, "text/xml");
    }
    return this(dom);
}

})(jQuery);

sigh.

:/

Candy Beard
 
2010-01-12

ie 6? :(

persist
 
2010-01-12

well, I list it only cause it does work in it. If it works there, it'll work in ie6, 7, +

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFront End

jquery XML DOM fix for IE 6