Simple RSS






3.65/5 (13 votes)
Build your own RSS reader with a couple of easy-to-use classes!
What is it?
![]() |
This article describes a simple RSS reader built on a couple of classes, RSSChannel and RSSItem . For an introduction to ![]() 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. |
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()
.
// Create the channel and fetch its items
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.
// Print titles of retrieved articles
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.