Binding RSS in Silverlight without Syndication classes

By Peter Bromberg

An easy way to bind RSS feed in Silverlight. Uses a LINQ Query.

string rss = (string)e.ReturnValue;
            XElement elem = XElement.Parse(rss);
            var items = elem.Descendants("item");
            var i = items.FirstOrDefault();
            string s =i.Element("description").Value!=null? (string)i.Element("description").Value:String.Empty;
            string t = (string)i.Element("title").Value;
            string l = (string)i.Element("link").Value;
            string p = (string)i.Element("pubDate").Value;
            var results = (from itm in items
                           select new RssItem()
                           {
                               title = (string)itm.Element("title").Value,
                               description = (string)itm.Element("description").Value,
                               link = (string)itm.Element("link").Value,
                               pubDate = (string)itm.Element("pubDate").Value
                           }).ToList();
            this.rssGrid.ItemsSource = results;

NOTE: The above assumes you are using the WebClient.DownloadStringAsync method. This is the code you would use inside the callback.

Binding RSS in Silverlight without Syndication classes  (968 Views)