Click here to Skip to main content
Click here to Skip to main content
Go to top

Simple RSS

, 15 Jan 2006
Rate this:
Please Sign up or sign in to vote.
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().

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

  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)

Share

About the Author

Ravi Bhavnani
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 2 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.
Follow on   Google+   LinkedIn

Comments and Discussions

 
GeneralThanks PinmemberHemant.Kamalakar28-Dec-07 23:53 
GeneralRe: Thanks PinmemberRavi Bhavnani29-Dec-07 4:17 
Thanks, Hemant!
 
/ravi
 
This is your brain on Celcius
Home | Music | Articles | Freeware
ravib(at)ravib(dot)com

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 15 Jan 2006
Article Copyright 2006 by Ravi Bhavnani
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid