What is it?
| This article describes a simple RSS reader built on a couple of classes, RSSChannel and RSSItem . For an introduction to , please see this Wikipedia article.
You use the reader by selecting a channel, clicking "Update" to retrieve the latest articles, selecting an entry in the article list, and clicking "View" to the view the article. The article is displayed in a new IE window.
Click here for an animated view |
How it works
The reader is based on a couple of classes, RSSChannel
and RSSItem
. RSSChannel
encapsulates an RSS feed while RSSItem
represents individual items in the feed. Retrieving a feed is as easy as constructing an RSSChannel
and calling fetchItems()
.
RSSChannel channel =
new RSSChannel ("ABC News - International",
"http://my.abcnews.go.com/rsspublic/world_rss20.xml");
channel.fetchItems();
The collection of articles is retrieved via the channel's Items
property. Each article is an instance of an RSSItem
object and exposes a few commonly used attributes such as the article title, description, URL, author and publication timestamp.
foreach (RSSItem rssItem in channel.Items)
Console.Writeln (rssItem.Title);
RSSChannel
works by downloading and parsing the content made available at the channel URL. All the "heavy lifting" is done by the WebResourceProvider and StringParser classes, described elsewhere at CodeProject.
RSSChannel
RSSChannel
works by downloading the content offered by the RSS feed, parsing the XML document, and extracting the channel's title, publication timestamp and collection of items. The base WebResourceProvider class takes care of the task of retrieving the content and calls RSSChannel
's parseContent()
override, which does the following:
- Get the
<rss>
element - fail if none.
- Get the value of the contained
<channel>
element - fail if none.
- Get the value of the contained
<title>
element - fail if none.
- Get the value of the optional
<pubDate>
or <lastBuildDate>
element.
- Construct an
RSSItem
from every contained <item>
element.
RSSChannel
exposes the following properties:
Items | | Gets the collection of articles (RSSItem s) in the channel. |
Name | | Gets and sets the channel's name. |
Title | | Gets the channel's title. |
Updated | | Gets the channel's updated timestamp. |
RSSChannel
also contains other properties (and methods) inherited from the WebResourceProvider class from which it derives.
RSSItem
RSSItem
represents a single item (i.e. article) in the RSSChannel
and works by constructing itself from an <item>
element present contained within the feed's <channel>
element. See this link for a complete list of sub-elements contained within <item>
.
RSSItem
exposes the following properties:
Author | | Gets the article's author. |
Description | | Gets the article's description. |
Link | | Gets the article URL. |
Published | | Gets the article's publication time. |
PublishedAsString | | Gets the article's publication timestamp as a string. |
Title | | Gets the article's title. |
Revision History
- 15 Jan 2006
Initial version.
Ravi Bhavnani is an ardent fan of Microsoft technologies who loves building Windows apps, especially PIMs, system utilities, and things that go bump on the Internet. During his career, Ravi has developed expert systems, desktop imaging apps, marketing automation software, EDA tools, a platform to help people find, analyze and understand information, trading software for institutional investors and advanced data visualization solutions. He currently works for a company that provides enterprise workforce management solutions to large clients.
His interests include the .NET framework, reasoning systems, financial analysis and algorithmic trading, NLP, HCI and UI design. Ravi holds a BS in Physics and Math and an MS in Computer Science and was a Microsoft MVP (C++ and C# in 2006 and 2007). He is also the co-inventor of 3 patents on software security and generating data visualization dashboards. His claim to fame is that he crafted CodeProject's "joke" forum post icon.
Ravi's biggest fear is that one day he might actually get a life, although the chances of that happening seem extremely remote.