jQuery XML find first node Attribute by nodename
Hi
I have an XML feed which has duplicate media:thumbnail child nodes for item
<item>
<title>Taylor's trial 'neo-colonialist'</title>
<description>The lawyer for Liberia's ex-President Charles Taylor says the prosecution has turned the war crimes trial into a "21st Century form of neo-colonialism".</description>
<link>http://www.bbc.co.uk/go/rss/int/news/-/news/world-africa-12685938</link>
<guid isPermaLink="false">http://www.bbc.co.uk/news/world-africa-12685938</guid>
<pubDate>Wed, 09 Mar 2011 13:12:32 GMT</pubDate>
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/51143000/jpg/_51143152_taylor103244920.jpg"/>
<media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/51592000/jpg/_51592942_011213879-1.jpg"/>
</item>
<item>
<title>Seven children die in US farm fire</title>
<description>Seven children, aged from seven months to 11 years old, die in a fire at a farmhouse in the borough of Blain in the US state of Pennsylvania.</description>
<link>http://www.bbc.co.uk/go/rss/int/news/-/news/world-us-canada-12690685</link>
<guid isPermaLink="false">http://www.bbc.co.uk/news/world-us-canada-12690685</guid>
<pubDate>Wed, 09 Mar 2011 16:44:06 GMT</pubDate>
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/51596000/jpg/_51596640_trooper.jpg"/>
<media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/51597000/jpg/_51597027_pennhousefire3-304x171.jpg"/>
</item>
IF I Try to get the first node using :first, it doesn't work at all
var thumb = $(this).find('[nodeName=media:thumbnail]:first)').attr('url');
IF I Try to get the first node using :eq(0) , I get the URL as undefined.
var thumb = $(this).find('[nodeName=media:thumbnail]:first)').attr('url');
Here is my complete code.
$('#output').empty();
$(xml).find("item").each(function()
{
var title = $(this).find('title').text();
var pubDate = $(this).find('pubDate').text();
var description = $(this).find('description').text();
var thumb = $(this).find('[nodeName=media:thumbnail]:eq(0))').attr('url');
var listItem = $('<li><img src=' + thumb + ' /><br/>' + title + pubDate + '<br/>' + description + '</li>');
$("#output").append(listItem);
});
Thanks
Rajesh