Consuming RSS Feed using XmlTextReader and DataSet

You are currently viewing Consuming RSS Feed using XmlTextReader and DataSet

RSS Feed is a very popular web feed format to publish frequently updated contents such as blog entries, articles, news headlines. In the following tutorial, I will show you how you can read RSS feed from its URL using XmlTextReader class in System.Xml namespace. I will also show you how you can bind and display feed contents using ASP.NET DataList control.

First, I am creating a simple ASP.NET web form which ask you to type and check different RSS Feed URLs from different websites. You can also use hard coded string URL in your application, or it can be stored in database if you have large website, and you have many different RSS Feed URLs to display. The following figure shows the preview of the web form with the RSS feed results.

Following code shows how to read RSS feed from the URL in XmlTextReader and DataSet object.

protected void Button1_Click(object sender, EventArgs e)
    XmlTextReader reader = new XmlTextReader(TextBox1.Text);
    DataSet ds = new DataSet();
    DataList1.DataSource = ds.Tables[2];

Following is the html source code to bind the DataSet table fields title and link with a DataList control.

<asp:DataList ID="DataList1" runat="server" CellPadding="4" ForeColor="#333333" BorderColor="#336699" BorderStyle="Solid" BorderWidth="1px">

   <AlternatingItemStyle BackColor="#CCCCFF" />
   <HeaderStyle BackColor="#336699" Font-Bold="True" ForeColor="White" />

      Latest Tutorials

      <asp:HyperLink ID="link" runat="server" Text='<%# Eval("title") %>' NavigateUrl='<%# Eval("link") %>' />                
READ ALSO:  Overview of C# Anonymous Types

This Post Has 2 Comments

  1. Muhammad Usman Iqbal

    very good helping material for quick learning.

  2. Muhammad Zeeshan

    Its nice u have demonstrated a good example.

Leave a Reply