Testcase for jQuery Ticket 6491

xml loading NS bug?

by jitter

HTML

<p>XML is requested which is an RSS feed.<br />Then we try to find title as descendant of item.<br />There is &lt;item>&lt;media:content>&lt;title> and &lt;item>&lt;title></p>
<h2>$(data).find('item title')</h2>
<div id="one"></div>
<h2>$(data).find('item>title')</h2>
<div id="two"></div>

CSS

h2 { color: red }

JavaScript

var rss = '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>channel title</title><link>http://example.com</link><description>News</description><item><title>item title</title><description>text</description><media:content url="http://example.com" medium="image"><media:title type="html">media title</media:title></media:content></item></channel></rss>';

$.ajax({
    url: "/echo/xml/",
    type: "POST",
    dataType: "xml",
    data: {
        xml: rss
    },
    success: function(data) {
        //note: no direct child selector used
        $(data).find("item title").each(function() {
            $("#one").append("<p>" + $(this).text() + "</p>");
        });
    }
});

$.ajax({
    url: "/echo/xml/",
    type: "POST",
    dataType: "xml",
    data: {
        xml: rss
    },
    success: function(data) {
        //note: direct child selector *used*
        $(data).find("item>title").each(function() {
            $("#two").append("<p>" + $(this).text() + "</p>");
        });
    }
});