Bug Tracker

Ticket #155 (new enhancement)

Opened 2 years ago

Last modified 1 week ago

Get Namespaced Elements in XML Documents

Reported by: slantedtiles@… Assigned to: anonymous
Type: enhancement Priority: minor
Milestone: 1.2.4 Component: core
Version: Keywords:
Cc: Needs: Review

Description (last modified by flesler) (diff)

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?

Attachments

Change History

Changed 2 years ago by john

  • priority changed from major to minor
  • description changed from 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? to 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?

Changed 1 year ago by andyzzz

ativan diflucan ativan ativan celexa sonata ativan imitrex flomax ativan levitra levitra guaranteed cheapest online levitra com cialis levitra prescriptionscom viagra cialis levitra levitra clinical data cialis levitra sales viagra buy levitra online viagra cialis levitra levitra viagra buy levitra levitra softabs buy levitra online levitra online discount levitra order levitra levitra danger viagra cyalis levitra compared cialis compare levitra viagra which is better viagra cialis or levitra flonase levitra myonlinemeds biz nexium stimula nexium celebrex levitra nexium propecia renova valtrex viagra nexium side effects new yorker prilosec nexium between difference nexium prilosec nexium pharmacy paxil wiki levitra generic paxil paxil ultram lexapro paxil prozac zoloft paxil side effects prozac zoloft paxil zoloft versus paxil prozac vs paxil paxil vs zoloft paxil versus zoloft buspar celexa prozac paxil anafranil paxil withdrawal symptoms how to switch from paxil to celexa paxil zoloft between difference paxil zoloft paxil vs prozac depression celexa vs paxil prozac paxil paxil prozac vs zoloft or paxil zoloft paxil prozac prozac interactions with viagra cialis levitra ultram and prozac drug interaction prozac ultram prozac nation prozac side effects lexapro paxil prozac zoloft prozac zoloft paxil prozac vs paxil soma buy cialis levitra low online pharmacy price soma viagra drug interaction soma ultram drug soma akane soma buy soma soma mandal buy soma online prozac soma soma carisoprodol online prozac soma boards chongqed carisoprodol generic soma viagra cialis phentermine soma carisoprodol soma soma pharmacy buy cheap drugs lipitor tricor cardizem soma soma prozac soma online zoloft levitra lipitor online pharmacy pharmacy zoloft phentermine levitra low price pharmacy zoloft phentermine viagra ultram zoloft zoloft ultram zoloft ultram interaction zoloft side effects zoloft litigation weight, zoloft vs. lexapro zoloft versus lexapro lexapro zoloft zoloft and lexapro zoloft vs lexapro zoloft lexapro side effects lexapro versus zoloft zoloft lexapro comparison lexapro vs. zoloft changing from zoloft to lexapro weight gain more zoloft or lexapro which is better for anxiety lexapro or zoloft lexapro paxil prozac zoloft zyrtec levitra myonlinemeds biz vaniqa zyrtec myonlinemeds biz ultram ultram zyrtec 2737 aid amerimedrx com ultram zyrtec allegra claritin zyrtec claritin allegra zyrtec zyrtec cetirizine hcl lots of allergies just one zyrteco zyrtec clartin allegra zyrtec and allegra used together zyrtec and allegra combined combining allegra with zyrtec to treat hives zyrtec vs allegra myonlinemeds biz nexium zyrtec allegra zyrtec zyrtec claritin claritin zyrtec allegra vs zyrtec zyrtec and allegra zyrtec zantac error zyrtec side effects carisoprodol valium zyrtec

Changed 11 months ago by Orange

Is there any improvement on that point planned ? In jQuery-1.2.1.js, it's only two changes to add on lines :

1260 : c.nodeName.replace(/^.*:/,'').toUpperCase() instead of c.nodeName.toUpperCase() 1284 : n.nodeName.replace(/^.*:/,'').toUpperCase() instead of n.nodeName.toUpperCase()

Hope this will be implemented as it blocks the use of jQuery with namespaced XMLs.

Orange

Changed 8 months ago by george.petrov

any status on this one? Seems still not implemented...

Changed 5 months ago by mihxil

Can I vote for this bug to be fixed?

Changed 4 months ago by flesler

  • need set to Review
  • description changed from 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? to 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?

What about supporting $('b\:foo') like with attribute selectors ?

This could just handled with a plugin with something like:

$.nsTag = function( name ){

return $(document.getElementsByTagName(name));

};

$.nsTag('b:foo')... (any jQuery method)

Changed 4 months ago by flesler

  • milestone set to 1.2.4

Changed 1 week ago by timothy.davis

This seems to not have made it into 1.2.4 http://dev.jquery.com/report/27. Can you update when this will be fixed? $(xml).find('ns:elementName').text() would be nice

Note: See TracTickets for help on using tickets.