Click here to Skip to main content
11,414,516 members (68,517 online)
Click here to Skip to main content

RSS Reader

, 17 Feb 2004
Rate this:
Please Sign up or sign in to vote.
An easy to use RSS feed reader.
<!-- Article image -->

Sample Image - RssReader.gif


Introduction

There's already quite a comprehensive RSS tool on The Code Project: RSS 2.0 Framework written by "Jerry Maguire". The purpose of this, RssReader class, is to provide a simple tool for retrieving RSS feeds from remote and local sources, without needing to parse XML in each application you require the RSS feed in. The class, as its name suggests, only reads RSS feeds - it has no capabilities for writing feeds.

The RSS Format

The RSS (Really Simple Syndication) specification is found at http://blogs.law.harvard.edu/tech/rss. It's an XML format for retrieving, typically, headlines or the latest article details from other sites. For example the New York Times provide an RSS feed of their main headlines, which you can access and put inside your own site or application.

The RSS format is true to its name - simple. As the image below shows, it contains a root RSS node, which has a channel node beneath it. Inside this channel node there are a number of elements to describe the feed. Then after these is a list of articles, headlines, stories or whatever they contain in the form of item nodes.  Each item node contains elements to describe themselves - title, description and link are the 3 required elements, there are other optional ones which you can be read about in the specification and the RssReader class docs.

Typical XML format of an RSS document

RssFeed and RssItem objects

Given the simpilicity of the RSS format, it was straightforward to map its structure to a value type (struct).The image below shows the RssFeed object.

RssFeed object
 

In this are most (some haven't been implemented in this version) of the fields that RSS offers. There is an Items property, which contains a collection of RssItem objects. The RssItem type maps to an RSS item, containing most of the fields available to an RssItem.

RssItem object

The RssReader class has one main method, RetrieveFeed which returns an RssFeed object, given a url. This url can be in the format of file:// as well as the standard http://, if you want to open a local file (it's not been tried with ftp://).

Static methods

I added several static methods to make the process even simpler, they're all self explanatory. Also included in the class library is a class called RssHtmlMaker. This is a simple tool I wrote to turn a RssFeed object into a html (or any other format) document, given a template containing tokens. These tokensmap to the rss fields available. Details of the tokens are in the documentation.

RDF

Included in the RssReader is the ability to read simple RDF format feeds. RDF (Resource Description Framework) is an W3C XML format for describing web resources. The format caters for describing the content of the web resource, including items such as title, description and url. There were a couple of RDF feeds which i wanted to use, specifically the slashdot.org feed and the register.com feed. The main way these RDF documents differ
from their RSS counter-parts is the the <items> nodes are children of the main root rss (or in this case rdf) node, rather than the <channel> node.. This is catered for in the RssReader class via the member variable RdfMode, which is set to false by default. The RDF specification is found at http://www.w3.org/TR/2004/REC-rdf-primer-20040210/ .

Final note

One final thing to note: to save yourself at worst being ip-banned by the hosts of the feeds, and at best just upsetting the feed providers, I'd recommend caching the feeds once you get them, rather than retrieving the feed each time it's required. This can be done by serializing the RssFeed class, or creating a html version of the feed and saving it to disk.

Hopefully the class is useful to people - I've not managed to find any C# Rss Feeds about, if there are any then leave a url below.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

yetanotherchris
Web Developer
United Kingdom United Kingdom
London based C# programmer.

I maintain my own pet C# site http://www.sloppycode.net in my spare time.

Comments and Discussions

 
GeneralClass doesn't allow retrieving CDATA content for the &lt;description&gt; tag Pin
craigg75, 29-Sep-09 16:00
membercraigg7529-Sep-09 16:00 
QuestionLicense for commercial use ? Pin
michal.ziomek, 4-May-09 1:45
membermichal.ziomek4-May-09 1:45 
QuestionHow to read old feeds Pin
satalaj, 2-Mar-09 19:43
membersatalaj2-Mar-09 19:43 
QuestionLicense? Pin
Member 4248908, 31-Jan-09 23:34
memberMember 424890831-Jan-09 23:34 
GeneralpubDate-Bug Pin
Member 2904090, 9-Dec-08 0:38
memberMember 29040909-Dec-08 0:38 
GeneralRe: pubDate-Bug Pin
alcobnitech, 5-Nov-09 20:40
memberalcobnitech5-Nov-09 20:40 
GeneralRe: pubDate-Bug [modified] Pin
CptHook, 9-Nov-10 23:37
memberCptHook9-Nov-10 23:37 
Generalnice Pin
ali_reza_zareian, 10-Jul-08 23:09
memberali_reza_zareian10-Jul-08 23:09 
GeneralHTML in the Description Pin
fodaley, 4-Jan-08 23:19
memberfodaley4-Jan-08 23:19 
GeneralRe: HTML in the Description Pin
fodaley, 5-Jan-08 0:09
memberfodaley5-Jan-08 0:09 
GeneralRe: HTML in the Description Pin
fodaley, 5-Jan-08 0:09
memberfodaley5-Jan-08 0:09 
GeneralSmall bug Pin
ehsoiueylkfjsegfoieuygfrlkeajrhg, 15-May-07 8:35
memberehsoiueylkfjsegfoieuygfrlkeajrhg15-May-07 8:35 
QuestionWhat would I need to do if I wanted to display feeds from more than one source at the same time Pin
bijhere, 16-Feb-07 6:09
memberbijhere16-Feb-07 6:09 
Generalreading only new feeds Pin
nitstheone, 20-Nov-06 9:32
membernitstheone20-Nov-06 9:32 
GeneralIssues with Special characters (á,é,í,ó,ú,ñ,etc) Pin
sesmac, 10-Nov-06 13:46
membersesmac10-Nov-06 13:46 
GeneralRe: Issues with Special characters (á,é,í,ó,ú,ñ,etc) Pin
smallguy78, 15-Nov-06 7:11
membersmallguy7815-Nov-06 7:11 
GeneralThanks! Pin
jamesjin, 26-Aug-06 8:42
memberjamesjin26-Aug-06 8:42 
GeneralAdding Enclosure support (here's how) Pin
hejndorf, 2-Feb-06 23:33
memberhejndorf2-Feb-06 23:33 
GeneralProblem making work with .NET 2.0 Pin
begin_busa, 27-Sep-05 1:16
memberbegin_busa27-Sep-05 1:16 
GeneralRe: Problem making work with .NET 2.0 Pin
smarkley, 23-Nov-05 10:49
membersmarkley23-Nov-05 10:49 
GeneralRe: Problem making work with .NET 2.0 Pin
Vasche, 28-Feb-06 6:28
memberVasche28-Feb-06 6:28 
More info on how to solve the issue using delegates, please?
GeneralRe: Problem making work with .NET 2.0 Pin
Vasche, 28-Feb-06 7:12
memberVasche28-Feb-06 7:12 
GeneralRe: Problem making work with .NET 2.0 Pin
k^s, 6-Oct-06 3:15
memberk^s6-Oct-06 3:15 
GeneralRe: Problem making work with .NET 2.0 Pin
smallguy78, 15-Nov-06 4:55
membersmallguy7815-Nov-06 4:55 
GeneralWhy didn't you add RDF auto detect Pin
wiseleyb, 2-Aug-05 1:53
susswiseleyb2-Aug-05 1:53 
GeneralCopy/Paste bug Pin
mav.northwind, 17-Jan-05 6:08
membermav.northwind17-Jan-05 6:08 
GeneralGreat RSS article Pin
PaKettle, 2-Oct-04 5:04
memberPaKettle2-Oct-04 5:04 
QuestionHow to I get more then one item from the rss feed Pin
bergetun, 29-Jun-04 5:00
memberbergetun29-Jun-04 5:00 
AnswerRe: How to I get more then one item from the rss feed Pin
Rodrigo Dias, 10-May-05 7:18
memberRodrigo Dias10-May-05 7:18 
GeneralRe: How to I get more then one item from the rss feed Pin
elie aintabi, 10-Jul-08 6:52
memberelie aintabi10-Jul-08 6:52 
AnswerRe: How to I get more then one item from the rss feed Pin
Antonio Dias, 10-Jul-08 7:21
memberAntonio Dias10-Jul-08 7:21 
General(407) Proxy Authentication Required. Pin
hex1848, 29-Mar-04 11:25
memberhex184829-Mar-04 11:25 
GeneralRe: (407) Proxy Authentication Required. Pin
smallguy78, 7-Apr-04 23:46
membersmallguy787-Apr-04 23:46 
GeneralRe: (407) Proxy Authentication Required. Pin
begin_busa, 27-Sep-05 1:57
memberbegin_busa27-Sep-05 1:57 
AnswerRe: (407) Proxy Authentication Required. Pin
snort, 11-Sep-07 3:14
membersnort11-Sep-07 3:14 

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 | Terms of Use | Mobile
Web01 | 2.8.150427.2 | Last Updated 18 Feb 2004
Article Copyright 2004 by yetanotherchris
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid