Skip to main content

Bug Tracker

Side navigation

#6798 closed bug (invalid)

Opened July 19, 2010 12:45AM UTC

Closed July 21, 2010 02:11AM UTC

XML parsing fails with different keywords in different browsers

Reported by: llimllib Owned by:
Priority: Milestone: 1.4.3
Component: core Version: 1.4.2
Keywords: xml webkit firefox mac Cc:
Blocked by: Blocking:
Description

Using Chrome 5.0.375.99 beta, Safari Version 5.0 (5533.16), and Firefox 3.5.10, all on Mac OS X 10.5.8, these tests return different values:

test("jQuery XML bug", function() {
    expect(3);
    equals(jQuery('<?xml version="1.0" ?><x><html></html></x>').children().length, 1, "fails in both webkit and firefox");
    equals(jQuery('<?xml version="1.0" ?><x><title></title></x>').children().length, 1, "fails in webkit but not firefox");
    equals(jQuery('<?xml version="1.0" ?><x><titles></titles></x>').children().length, 1, "works on both");
});

Different keywords will cause this bug to occur on each of the browsers. Here's the results of a brief test on Firefox:

>>> function test(t) { return jQuery("<x><"+t+">testing</"+t+"></x>").find(t).length; }
>>> jQuery.map(["title", "Title", "span", "div", "html", "body", "h1", "script", "em"], function(x) { return [x, test(x)]; });
["title", 1, "Title", 1, "span", 1, "div", 1, "html", 0, "body", 0, "h1", 1, "script", 0, "em", 1]

and on Chrome:

> function test(t) { return jQuery("<x><"+t+">testing</"+t+"></x>").find(t).length; }
> jQuery.map(["title", "Title", "span", "div", "html", "body", "h1", "script", "em"], function(x) { return [x, test(x)]; });
["title", 0, "Title", 0, "span", 1, "div", 1, "html", 0, "body", 0, "h1", 1, "script", 0, "em", 1]

This bug matters to me, and I discovered it because the XML returned by the Amazon Ecommerce web service appears to parse correctly, but the <title> attribute just seems to have disappeared.

Attachments (0)
Change History (4)

Changed July 19, 2010 02:21AM UTC by llimllib comment:1

By the way, the bit of the docs that made me think that this should work properly is this:

When XML data is returned from an Ajax call, we can use the $() function to wrap it in a jQuery object that we can easily work with. Once this is done, we can retrieve individual elements of the XML structure using .find() and other DOM traversal methods.

from http://api.jquery.com/jQuery/

Changed July 19, 2010 02:29AM UTC by llimllib comment:2

Also, the <title> information appears to be lost at line 489 of src/manipulation.js .

I'm happy to make a fix and submit a patch, but I'd need to be instructed on how you'd like this fixed as it's non-obvious. Should there be another code path for XML than for HTML?

Anyway, if you want to tell me, I'm happy develop a patch, otherwise, I'm afraid I wouldn't be helping much to try and develop one any further.

Changed July 19, 2010 04:40AM UTC by llimllib comment:3

(OK, I fixed my bug by returning responseXML instead of responseText from the Amazon library I'd written. So my question is: should $(xhr.responseText) work like $(xhr.responseXML)?)

Changed July 21, 2010 02:11AM UTC by dmethvin comment:4

resolution: → invalid
status: newclosed

As you found,

$()
is for parsing HTML, not XML. If you pass an XML *tree* of nodes to $() it will wrap them fine. It does not parse XML.