Click here to Skip to main content
15,892,005 members
Articles / Programming Languages / XML
Article

RSS Consumer

Rate me:
Please Sign up or sign in to vote.
4.14/5 (11 votes)
12 May 2005CPOL2 min read 75K   1.1K   35  
Building an application to read RSS feeds.

Sample Image

Introduction

RSS Consumer is an RSS client that reads RSS feeds from any URL that points to an XML file over the web. It also allows the user to save any other non-RSS links. The user can arrange and organize his links by creating groups, that are saved in an XML file called the XMLFeedLibrary.xml, stored in a separate folder under the application folder.

The application is developed in .NET using C# and XML.

Background

An RSS feed is a regularly updated XML document that contains metadata about a news source and the content in it. Minimally, an RSS feed consists of a channel that represents the news source, which has a title, link, and description that describe the news source. Additionally, an RSS feed typically contains one or more item elements that represent individual news items, each of which should have a title, link, or description.

Note: The aforementioned elements appear in most RSS feeds but are not the only ones that can appear. Many RSS feeds also contain additional elements such as date or language. However, these elements and many others appear less commonly in practice.

There are many advanced RSS aggregators and clients available for free over the net. Requirements to develop an RSS aggregator is available at MSDN.

Using the RSS Consumer

To use the RSS Consumer, you need to first install the .NET framework on your machine. The interface is quite simple to use.

The application makes good use of the System.Xml library. The feeds are read by using the xmlDocument.Load() method of the xmlDocument object. The following code block explains how the RSS feeds are read and listed in the feed listview control. Once the links are listed, the user can browse each of the links by a single click.

C#
public void FetchFeedInfo(string strFeedURL, string SearchNodeText)
{
    try
    {
        if(!SearchNodeText.Trim().Equals(""))
        {
            ClearFeedList();
            this.Cursor=Cursors.WaitCursor;
            XmlDocument xDoc=new XmlDocument();
            xDoc.Load(strFeedURL);
            //xDoc.Load("http://msdn.microsoft.com/rss.xml");
            //xDoc.Load("http://surya.somee.com/rss/rss.xml");
            XmlNodeList xnList= 
              xDoc.DocumentElement["channel"].SelectNodes(SearchNodeText);
            foreach(XmlNode xNode in xnList)
            {
                ListViewItem lstFeedItem=new ListViewItem();
                for(int i=0;i < xNode.ChildNodes.Count;i++)
                {
                    //lstFeedItem.Text=Convert.ToString(lstvFeed.Items.Count+1);
                    lstFeedItem.ImageIndex=0;
                    if(i==0)
                    {
                        lstFeedItem.SubItems.Add(xNode.ChildNodes[0].InnerText);
                        lstFeedItem.SubItems.Add("");
                        lstFeedItem.SubItems.Add("");
                        lstFeedItem.SubItems.Add("");
                    }
                    if(i==1)
                    {
                        lstFeedItem.SubItems.Add(
                          xNode.ChildNodes[1].InnerText.Substring(0,10));
                    }
                    if(i==2)
                    {
                        lstFeedItem.SubItems.Add(xNode.ChildNodes[2].InnerText);
                        lstFeedItem.Tag= xNode.ChildNodes[2].InnerText;
                    }
                }
                lstvFeed.Items.Add(lstFeedItem);
            }
            this.Cursor=Cursors.Default; 

            //navigate to the first item
            if(lstvFeed.Items.Count>0)
            {
                Object o=null;
                lstvFeed.Items[0].Selected=true;
                axWebBrowserFeed.Navigate(lstvFeed.SelectedItems[0].Tag.ToString(), 
                                                          ref o,ref o,ref o,ref o);
            }
         }
         else
         {
             //
         }
     }
     catch(Exception ex)
     {
         this.Cursor=Cursors.Default;
         MessageBox.Show(ex.Message + " : " + ex.StackTrace);
     }
}

License

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


Written By
Team Leader
India India
Techincal Architect

16 years of overall work experience.

Proven Expertise in Agile process implementation.

Managed complex projects through their lifecycle.

Methodologies used include Agile, SDLC, Waterfall models.

Comments and Discussions

 
-- There are no messages in this forum --