Click here to Skip to main content
13,197,804 members (45,622 online)
Click here to Skip to main content
Articles » Languages » XML » General » Downloads


47 bookmarked
Posted 24 Feb 2010

What is RSS, and reading and writing RSS feeds

, 24 Feb 2010
This article explains what RSS is and how we can read and write RSS feeds.
using System;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.Xml.XPath;
using System.Text;
using System.Net;
using System.IO;

public partial class CricinfoAspNet : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void btnCricinfo_Click(object sender, EventArgs e)
        //  create here table and columns that will be used 
        //  for storing items from the xml file for later binding into grid 
        DataTable dtable = new DataTable();
        dtable.Columns.Add(new DataColumn("Match Name"));
        dtable.Columns.Add(new DataColumn("View Match"));

        //  fetch webrequest. Here, give the path of the location where rss feed is stored.
        WebRequest WebReq = WebRequest.Create("");
        //get webresponse from the webrequset 
        WebResponse webRes = WebReq.GetResponse();

        //use stream to stremline the input from from webresponse.
        Stream rssStream = webRes.GetResponseStream();

        //  Create new xml document and load a XML Document
        //  with the strem.
        XmlDocument xmlDoc = new XmlDocument();
        //loads the url from the stream

        //  use XmlNodeList to get the matching xmlnodes from the xmldocument
        XmlNodeList xmlNodeList = xmlDoc.SelectNodes("rss/channel/item");

        //create array of the object for creating the row
        object[] RowValues = { "", "" };

        //Make a Loop through RSS Feed items
        for (int i = 0; i < xmlNodeList.Count; i++)
            XmlNode xmlNode;

            xmlNode = xmlNodeList.Item(i).SelectSingleNode("title");
            if (xmlNode != null)
                RowValues[0] = xmlNode.InnerText;
                RowValues[0] = "";

            xmlNode = xmlNodeList.Item(i).SelectSingleNode("guid");
            if (xmlNode != null)
                RowValues[1] = xmlNode.InnerText;
                RowValues[1] = "";
            //  creating datarow and add it to the datatable
            DataRow dRow;
            dRow = dtable.Rows.Add(RowValues);
        //  finally bind the grid....
        grvRSS.DataSource = dtable;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


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


About the Author

Indrajeet Sutar
Software Developer (Junior) Excel Informatics, Pune
India India
Am Indrajeet T. Sutar. I am a web developer. I am working on .net technology. I have completed my Masters in Computers and Management (people call it as MCA, MBA etc.) Apart from programming i do photography (not regularly though), traveling and reading books.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171020.1 | Last Updated 24 Feb 2010
Article Copyright 2010 by Indrajeet Sutar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid