I've recently had the need to improve jQuery's selector support for XML
nodes with prefixes. In theory, it should be possible for a node with
the node name "D:response" to be selected using just "response", in
accordance with getElementsByTagName's rules. There's two issues that
prevent that, which I've included fixes for.
The first is that IE supports getElementsByTagName incorrectly, and
treats prefixes as part of the tag name. Using rev 234, lines 1228-1233
could be replaced with this:
for ( var i = 0; i < ret.length; i++ ) {
// create an array of tagnames to search for
var tags = {};
// fix for IE leaving in node prefixes
if (jQuery.browser.msie && ret[i].xml !== undefined && m[2] != '*')
for (var regex = new RegExp('</?((?:[^:]+:)?' + m[2] + ')\b', 'g'), tag;
(tag = regex.exec(ret[i].xml)) != null; tags[tag[1]] = true);
else tags[m[2]] = true;
for ( var tag in tags )
r = jQuery.merge( r, tag == "*" ?
jQuery.getAll(ret[i]) :
ret[i].getElementsByTagName(tag));
}
If it detects that we're searching an XML document and IE is being used,
it'll find all node names with the correct local name, get their
complete node names with prefixes, and search for each of those in turn.
If IE is not being used or we're searching an HTML document, it'll
search only for the specified tag name, so the overhead seems rather
minimal.
The second issue is that jQuery prevents nodes with prefixes from being
preserved in the filter function, specifically because of line 1014:
"": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
Which could be replaced with:
"": "m[2]== '*'||a.nodeName.replace(/[^:]+:/,
'').toUpperCase()==m[2].toUpperCase()";
That'll make sure only the local name is being compared instead of the
complete node name. (The best solution would be to use a.localName, but
IE doesn't support it, of course...)
If you could look this over and send a reply, I'd be very grateful.
— Mitchell Lane
PS: The next step to this would be adding support for a namespace
resolver, perhaps as a third parameter of $() and by using the CSS
syntax ("D|response"). Would you have any interest if I were to try and
write support for that?