RSSReader |
The RssReader class provides a number of static methods for easy 1 or 2 step retrieval of RSS feeds. RSS feeds can be downloaded from any URL, and are then parsed into an RssFeed data type, which contains properties representing most aspects of an RSS Feed. A number of events are available for the calling application to register at the various stages of the feed request and parsing. The following example retrieves the RSS news feed for the BBC news website, and creates a HTML document from the feed's details. It saves the HTML document to disk, and launches the default browser with the document. The number of items displayed is limited to 5. If there is any error, a messagebox is displayed with the details of the error. RssFeed feed = RssReader.GetFeed("http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/front_page/rss091.xml"); if ( feed.ErrorMessage == null || feed.ErrorMessage == "" ) { string template = "<a href=\"%Link%>%Title%</a><br/>%Description%<br/><br/><ul>%Items%</ul>"; string itemTemplate = "<li><a href=\"%Link%>%Title%</a><br/>%Description%</li>"; string html = RssReader.CreateHtml(feed,template,itemTemplate,"",5); StreamWriter streamWriter = File.CreateText("c:\\rss.html"); streamWriter.Write(html); streamWriter.Close(); System.Diagnostics.Process.Start("c:\\rss.html"); } else { MessageBox.Show("Error getting feed:\r\n" +feed.ErrorMessage,"Rss Demo App",MessageBoxButtons.OK,MessageBoxIcon.Exclamation); } |