.Net, ASP.Net, C#, VB.net, SQL Server, Xml, CSS, Design Patterns related tips, tricks, code snippets, articles, links, thoughts, etc. from Binu & Subi Thayamkery.

Binu Thayamkery is a seasoned software architect with more than 13 years of experience in developing enterprise grade connected systems using Microsoft Technologies. In his current position as a lead consultant-solution architect with Prudential Financial, he is working on architecture of next generation investment reporting framework using .net 3.5/WCF/AJAX, etc. He holds a Masters Degree in Computer Science from Colorado State University. Subi Thayamkery is an experienced software developer with more than 8 years of developing various application software systems ranging from workflow automation systems to compliance management tools. She currently works as a technology consultant for Prudential Financial where she helps develop a new system for corportate governance department. She holds an Electrical Engineering degree from New Jersey Institute of Technology.

Friday, February 03, 2006

Content Syndication using RSS

RSS is a popular format for syndicating content over the web. As a website owner, you attract more repeat customers to your site if you allow the users to consume your content using content aggregation technology like RSS. At the users end, they can use a feed aggregator or any RSS Reader software to read your published content.

Here is the Wiki definition of RSS,

RSS is a family of XML dialects for Web syndication used by (among other things) news websites and weblogs. The abbreviation is used to refer to the following standards:

  • Rich Site Summary (RSS 0.91)

  • RDF Site Summary (RSS 0.9 and 1.0)

  • Really Simple Syndication (RSS 2.0)


The technology of RSS allows Internet users to subscribe to websites that have provided RSS feeds; these are typically sites that change or add content regularly. To use this technology, site owners create or obtain specialized software (such as a content management system) which, in the machine-readable XML format, presents new articles in a list, giving a line or two of each article and a link to the full article or post.


Since Netscape's creation of original version of RSS ( ver 0.90 ), it has gone through many
revisions. (0.91, 0.92, 0.93, 0.94...1.0 and now 2.0). The format of RSS 2.0 looks like this,

<rss version="2.0" xmlns:dc="http://directkerala.com/ns/">
<channel>
<title>DirectKerala.com</title>
<link>http://www.directkerala.com/</link>
<descriptionvDirect Kerala is Kerala's no.1 portal</description>
<item>
<title>Movie Review - Rajamanikyam</title>
<link>http://www.directkerala.com/movies/rajamanikyam.aspx</link>
<description>Mammootty’s Midas touch- Rajamanikyam....</description>
<dc:creator>DirectKerala</dc:creator>
<dc:date>2006-02-02</dc:date>
</item>

</channel>
</rss>

Here is a sample ASP.Net program that shows you how to create your own RSS Feed.
In this example, I have a page named rss.apsx , and the following is code for its Page_Load


private void Page_Load(object sender, System.EventArgs e)
{
Rss r = new Rss();
DataSet ds = GetData();
r.OutputStream = Response.OutputStream;
r.RssTitle = "DirectKerala.com";
r.PublisherUrl = Request.Url.Host;
r.Description = "DDirect Kerala is Kerala's no.1 portal";
r.Copyright = "Copyright (C) Direct Kerala Online Services (P) Ltd, DBA DirectKerala.com.";
r.Generator = "DirectKerala.com RSS Generator";
r.ItemSource = ds;
r.ItemTitleField = "ListCaption";
r.ItemDescriptionField = "ListDesc";
r.ItemPublicationDateField = "ListStartDate";
r.ItemUrlField = "ListingCode";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
Rss.PublishRss(r);
Response.End();

}


GetData() is the function that gets me the data that need to be publised. The DataSet returned has fields like "ListCaption", "ListDesc",... etc. Make sure that the content type is set to text/xml and Rss.PublishRss() method will write the data in RSS 2.0 format to the Response stream.

To be Contd....

0 comments: