21.4.10

Parsing XML in IE

Recently a friend that was using an old Wrox xml parser (zxml.js) ran into some errors with the release of the most recent version of FireFox and needed a fix. I recommended an upgrade to the latest library but realizing he was using a wrox library he wanted to find something that he could be fairly certain would be supported moving forward. (Nothing against wrox, he just felt for whatever reason the authors may stop supporting it someday.)

I recommended jQuery because of other features that no website should be without and I had read in several blogs that it was possible to parse XML with jQuery out-of-the-bag. After a short tutorial on how to parse XML using jQuery, it was pretty awesome to have a prototype running on FF 3.x. in a few minutes with some really basic parsing code like this:
    $(document).ready(function(){
$(strXML).find("id").each(function() {
var item = $(this);
alert(item.attr('name'));
});
});
My friend works for a large corporation so they were concerned with IE support all the way back to IE6 (at time of writing IE6 has an 8.9% market share.) Since its somewhat difficult to have more than one IE install on a PC and the fact that my PC was in pieces on my office floor, I took the lazy route and installed WineBottler. I am pretty happy with being able to test IE6 and 7 from the comfort of my cozy Mac.

I did a quick test in IE6, IE7, IE8 and to my dismay the XMLParser was failing. I hit Google again and found a solution to this problem. Which goes something like this:
    if($.browser.msie){
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.loadXML(strXML);
strXML = xml;
}
So this seems like a really simple fix and apparently its been a problem since IE6, so I don't understand why support isn't written into jQuery.

Its just another little IE burden, but isn't cross-browser-compatibility one of the primary goals?