1

I have a xml list that looks like this but with more items:

<item>
      <title>Arrests over Dhaka building collapse</title>
      <description>blabla.</description>
      <link>http://url.com</link>
      <pubDate>Sat, 27 Apr 2013 14:56:50 GMT</pubDate>
      <media:thumbnail width="66" height="49" url="http://news.com/bla2.jpg" />
      <media:thumbnail width="144" height="81" url="http://news.com/bla.jpg" />
</item>

As you can see I have 2x media:thumbnails I want to always grab the last one that have 144 width and 81 height and never the first one. Its the img url I want to fill a variable with.

This is my code:

var url = "http://news.com";
            XNamespace dcM = "http://search.yahoo.com/mrss/";
            var xdoc = XDocument.Load(url);
            var items = xdoc.Descendants("item")
            .Select(item => new
            {
                Title = item.Element("title").Value,
                Description = item.Element("description").Value,
                Link = item.Element("link").Value,
                PubDate = item.Element("pubDate").Value,
                Myimage= (string)item.Element(dcM + "thumbnail").Attribute("url").Value

            })
            .ToList();

This code gives me random thumbnails sometimes it gives me the first one and sometimes the second one. I always want the last thumbnail. Any help is appreciated.

4

1 に答える 1