What joy, LINQ to XML
. This code example shows how you can use LINQ to XML to painlessly extract
content from an RSS feed. No more XPathDocument and etc, coded in minutes.
StringBuilder sb = new StringBuilder();
//test read
XNamespace slashNamespace = "http://www.w3.org/2005/Atom";
XDocument rssFeed = XDocument.Load(@"http://feeds.feedburner.com/Gasta");
var posts = from item in rssFeed.Descendants("item")
select new
{
Title = item.Element("title").Value,
Published = DateTime.Parse(item.Element("pubDate").Value),
Url = item.Element("link").Value,
Description = item.Element("description").Value
};
int i = 0;
foreach (var post in posts)
{
sb.Append("<a class=\"news_header\" href=\"" + post.Url + "\"><br />");
sb.Append(post.Title);
sb.Append("</a>");
sb.Append("<span class=\"author\">" + post.Published + "</span>");
sb.Append("<div class=\"description\"" + post.Description + "</div><br />");
}
ltr_html.Text = sb.ToString();
Want to read more, see the original article from Scott Gutherie @ http://weblogs.asp.net/scottgu/archive/2007/08/07/using-linq-to-xml-and-how-to-build-a-custom-rss-feed-reader-with-it.aspx