My head blows up, had been “optimizing” code for Safari all day long (will do all week long at least). Somewhat fun, am masochistic, you know… Anyway. Safari 1.x had a problem with parsing XML with namespaces (rss xml from feedburner for example) – now I know (thx to Alex), the same happens with Safari 2.x; cool.
Task: fix things on Safari without touching the original code. Ended up using extend-like wrapping/emulation á la Prototype.js (as Toxin concluded).
safariXMLNode = function(node) { this.node = node; }
safariXMLNode.prototype.getElementsByTagName = function ( tag )
{
var list = this.node.getElementsByTagName(tag);
if (!list.length) list = this.node.getElementsByTagNameNS("*", tag);
var r = new Array();
for (var i = 0; i < litem =" list[i];" tmpnode =" new" firstchild =" lItem.firstChild;" nodevalue =" lItem.firstChild.nodeValue;">
Yes I know this is pretty raw and not yet perfect, but the code I had to repair used getElementsByTagName, firstchild+nodevalue only, and I don’t code for fun (read: time is money). Okay, I’ll convert it to our inhouse framework, but that’s it.
Usage: when you parse the xml (probably from ajax response using responseXML) use the wrapper to emulate things. No, redefining the original getElementsByTagName on HTMLElement is a no go for Safari 2; sorry, but good idea :)
parseRSS: function(xml) {
if (safari) { xml = new safariXMLNode(xml); }