Click here to Skip to main content
15,867,453 members
Articles / Programming Languages / C#
Article

Simple RSS

Rate me:
Please Sign up or sign in to vote.
3.65/5 (13 votes)
15 Jan 2006CPOL2 min read 64.7K   942   48   17
Build your own RSS reader with a couple of easy-to-use classes!

What is it?

SimpleRss in action 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().

C#
// 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.

C#
// 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:

  1. Get the <rss> element - fail if none.
  2. Get the value of the contained <channel> element - fail if none.
  3. Get the value of the contained <title> element - fail if none.
  4. Get the value of the optional <pubDate> or <lastBuildDate> element.
  5. Construct an RSSItem from every contained <item> element.

RSSChannel exposes the following properties:

Items Gets the collection of articles (RSSItems) 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
Canada Canada
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.

Comments and Discussions

 
GeneralThanks Pin
Hemant.Kamalakar28-Dec-07 23:53
Hemant.Kamalakar28-Dec-07 23:53 
GeneralRe: Thanks Pin
Ravi Bhavnani29-Dec-07 4:17
professionalRavi Bhavnani29-Dec-07 4:17 
QuestionProxy Authentication Pin
Shishir Pandey30-Nov-06 16:57
Shishir Pandey30-Nov-06 16:57 
Dear Ravi

I am using a net connection through proxy with firewall enabled. I have tried many other rss readers from the code project. But none of them work. How is it that you are able to pass thorugh the proxy problem.

with regards
Shishir
AnswerRe: Proxy Authentication Pin
Ravi Bhavnani1-Dec-06 8:17
professionalRavi Bhavnani1-Dec-06 8:17 
GeneralRe: Proxy Authentication Pin
Shishir Pandey4-Dec-06 22:59
Shishir Pandey4-Dec-06 22:59 
QuestionCharacter set (french) Pin
mwa_lux14-Apr-06 12:27
mwa_lux14-Apr-06 12:27 
AnswerRe: Character set (french) Pin
Ravi Bhavnani14-Apr-06 12:40
professionalRavi Bhavnani14-Apr-06 12:40 
AnswerAh! Pin
Ravi Bhavnani14-Apr-06 14:01
professionalRavi Bhavnani14-Apr-06 14:01 
AnswerRe: Ah! Pin
mwa_lux15-Apr-06 9:58
mwa_lux15-Apr-06 9:58 
GeneralThanks for Thanks Pin
realhossam29-Mar-06 3:31
realhossam29-Mar-06 3:31 
Generalyour attentionThanks for Thanks Pin
realhossam29-Mar-06 3:30
realhossam29-Mar-06 3:30 
GeneralMissing 'SimpleRSSDemoForm.resx' Pin
BDisp22-Jan-06 0:32
BDisp22-Jan-06 0:32 
GeneralRe: Missing 'SimpleRSSDemoForm.resx' Pin
BDisp22-Jan-06 0:59
BDisp22-Jan-06 0:59 
GeneralRe: Missing 'SimpleRSSDemoForm.resx' Pin
Ravi Bhavnani22-Jan-06 4:49
professionalRavi Bhavnani22-Jan-06 4:49 
GeneralRe: Missing 'SimpleRSSDemoForm.resx' Pin
Ravi Bhavnani24-Jan-06 11:10
professionalRavi Bhavnani24-Jan-06 11:10 
GeneralNo Article Pin
Matthew Hazlett15-Jan-06 18:35
Matthew Hazlett15-Jan-06 18:35 
GeneralRe: No Article Pin
Ravi Bhavnani16-Jan-06 5:43
professionalRavi Bhavnani16-Jan-06 5:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.