Vimal Loganathan
Friday, November 30, 2007
What is RSS?

Really Simple Syndication (RSS) is syndicated information provided by site owners for easy follow up of site updates. For instance, you may want to track the updates on current news, stocks, latest technologies, new releases, and weather information from various sites. However, tracking them may be cumbersome as well as time consuming and may exhaust one's thirst for knowledge.

RSS is the solution for business entities to ensure that potential customers receive up to date information on their offerings and it helps Internet users to be up to date in their areas of interest with the least effort. They just need to register the sites with their RSS readers. These readers get their updates (changes from the previous connection), which is presented to them in an e-mail format.

Structure of RSS
RSS is simply an XML file with the header attribute which is followed by a attribute.

Site content in xml format.

This RSS version represents the version of the document that conforms to Current RSS version 2.0. Its predecessors are

" Rich Site Summary 0.91,
" RDF (Resource Description Framework) Site Summary 0.90.

How to generate RSS feeds using ASP.Net 2.0?

Generating RSS feeds is very simple in ASP.Net 2.0 compared to ASP.Net 1.1, thanks to the Data Controls such as GridView and SQL Data Source. These controls makes working easier as they allow us to access the database without writing a single line of code. Also the solution could be much more effective than by other means. Usually, developers write a bunch of code-behind logic for their RSS feed generation. In the conventional RSS feed generation, to retrieve data, Select query is used to pull out all the data wanted from a back end database such as MS SQLServer. However the feed generation rendering takes a lot of time, leading to performance issues. The following simple steps can be followed to address this issue.

The five steps used to generate RSS feed for a site or application are as shown below:

Step 1:

Create a web form and remove all the contents inside .
Add the following attribute in the page directive,
The page directive looks like:
<%@ Page Language="C#"
ContentType="text/xml" %>

Step 2:

Now the page content is an XML. So, it is mandatory to mention the XML version of the page. Hence, add this tag in the page,

Now the page content looks like this:

<%@ Page Language="C#"
ContentType="text/xml" %>

Step 3:

Drag and drop the repeater control on the page.
In repeater control's header template, provide the valid RSS attribute and channel attribute. That is,

And in footer template close the RSS tag like this,

The Item Template should be like this:

<%# DataBinder.Eval(Container.DataItem, "XML_F52E2B61-18A1-11d1-B105-00805F49916B") %>

May be, the data-binding column may be confusing now, but proceed to the next step. This data-binding column is the alias generated for XML.

Finally, your repeater control will look like this:


<%# DataBinder.Eval(Container.DataItem, "XML_F52E2B61-18A1-11d1-B105-00805F49916B") %>

Step 4:

Drag and drop the SQL data source on your page.
Provide all your database connection strings and select custom query option.
In Select command, type your query with columns, which you wanted to expose to the users.
So your query will be
But this query will not be much useful in generating the RSS feed. We need to use the FOR XML clause in SQL server to generate XML data for the above-mentioned columns in Select query. Your query will be like,


In section of a Select query, title and link are necessary. If there are no title and link fields you can give an alias name for the suitable column.

Alternative approach:
If you feel that the connection string in design file is vulnerable then you can go for Object Data Source. Simply create a class and write a function to retrieve data for the above Select query and return it as data table.

Step 5:
Select the data source id of your repeater as SQL data source.

Now, execute the page in the browser. RSS feed is ready!

Advantages of using FOR XML:

This retrieves all the data and wraps them with the XML tag, and in repeater this will be rendered in a single shot; whereas the simple Select command retrieves the data and during the rendering process it internally executes the loop to display each row.

The author is a software Engineer at Real Soft Inc (India).He can be reached at technical@realsoftinc.com

Share on LinkedIn

Previous Magazine Editions