.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Implementing RSS and Atom Feed

Posted By:Nikhil Kumar       Posted Date: August 02, 2010    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  

In today s scenario, Internet surfers frequently download Web pages of their favorite websites and search the content for any updates. These websites range from news portals to job portals. Accessing websites in this way, however, consumes a lot of time since the surfers have to open the websites and browse their favorite pages for the updates. A much simpler approach is to access the updated content through the use of Web syndication
 

Implementing RSS and Atom Feed

 

In today s scenario, Internet surfers frequently download Web pages of their favorite websites and search the content for any updates. These websites range from news portals to job portals. Accessing websites in this way, however, consumes a lot of time since the surfers have to open the websites and browse their favorite pages for the updates. A much simpler approach is to access the updated content through the use of Web syndication

formats, such as Really Simple Syndication (RSS) and Atom.

Syndication of a Web page is a quick and easy way to create and use distributed or scattered content, such as breaking news Nowadays, RSS and Atom are used for many purposes, such as marketing, bug reporting, consistent updating, and publications. It is very common to see RSS or Atom on various blogs and community websites. RSS enables a website to send article previews and alerts to customers about new products and

upcoming events. In this appendix, you learn about RSS feed and Atom feed in detail.

 

RSS Feed

 

RSS is one of the Web feed formats used to keep you updated of the changes brought about in your website. A Web feed is used to provide frequently updated content of a Web page. It is a document (often XML-based) that contains content items with Web links. Web feeds are designed to be machine-readable (computer) rather than

human-readable. RSS too uses an XML code that constantly scans the content of a website for new updates and broadcasts them to users through the feed. When an update is sent, it includes a headline and a small amount of text, either a summary or a link to the whole text. Table B.1 lists the various versions of RSS:

 

Table B.1:

RSS Version Description

 

RSS 0.90 Designed by Netscape for building portals of headlines to news websites. This

version is not used nowadays. RSS 0.91 Proposed by Netscape, but developed by UserLand. Developers use this version for developing Web-based software. This version is called Rich Site Summary and is relatively easy to use. It is commonly used for basic

syndication and offers an easy migration path to developers. RSS 0.92, RSS 0.93, RSS 0.94 Developed by UserLand, this version allows richer metadata than 0.91, but has

now been replaced by 2.0.

 

 

Table B.1:

RSS Version Description

 

RSS 1.0 Developed by RSS-DEV Working Group, this format was based on Resource

Description Framework (RDF) and is used in applications where the use of

advance RDF-specific modules is desired. This ensures extensibility of a

website, which can be managed by more than one vendor.

RSS 2.0 Developed by UserLand, this version offers extensibility via modules and has

an easy migration path from the 0.9x branch. It is used for general-purpose and

metadata-rich syndication. It is also possible to get an RSS update automatically without any user intervention. This task is often performed by some special programs knows as Feedreader or aggregator. These are programs or Web applications that aggregate syndicated Web content, such as news headlines and blogs, and thereby reduce the time and effort by checking websites for updates. After it is subscribed to a feed, an aggregator is able to check for new content at user-determined intervals and retrieve the update. RSS readers or aggregators enable a website to provide with a combined view of its content in a single browser display or desktop application. An RSS document conforms to

XML 1.0 specifications, as published on the World Wide Web Consortium (W3C) website.

 

Here is the syntax of RSS 2.0:

Welcome to MyNewsSite1

http:// MyNewsSite1.com

News Update

Update 1

http:// MyNewsSite1.com/update1

Check out for todays business scoop

 

In the preceding syntax, the first line is the XML declaration that specifies the XML version of a document.

According to W3C, all RSS files must conform to the XML 1.0 specifications. Some elements and attributes used in the preceding syntax are explained as follows:

 

-Uses the version attribute to specify the version of RSS to which a document conforms. In the preceding syntax, the version attribute is set to 2.0 to specify that the RSS document conforms to RSS 2.0.

?? -Contains the metadata and acts like the headline of the channel. This element is nested within the element. There can be only one element in the RSS document. As shown in the preceding code, the element contains the following three attributes:

 

. -Specifies the name of the channel or the website corresponding to the channel.<o:p></o:p></p> <p class="MsoNormal">. <link>-Specifies the link of the home page of the website that corresponds to the channel.<o:p></o:p></p> <p class="MsoNormal">. <description>-Contains a phrase or sentence to describe the RSS feed.<o:p></o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><b><i><o:p> </o:p></i></b></p> <p class="MsoNormal"><b><i>Implementing RSS and Atom Feed<o:p></o:p></i></b></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal">The <channel> element supports a number of sub-elements, as listed in Table B.2:<o:p></o:p></p> <p class="MsoNormal"><b>Table B.2: Sub-Elements of the <channel> Element<o:p></o:p></b></p> <p class="MsoNormal"><b>Element Description<o:p></o:p></b></p> <p class="MsoNormal"><b><o:p> </o:p></b></p> <p class="MsoNormal"><i style=""><category> Specifies the category of the channel.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><cloud> Contains a notification for content updates.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><copyright> Contains information about the copyright material of a website.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><docs> Specifies the Uniform Resource Locator (URL) of the Web page containing the<o:p></o:p></i></p> <p class="MsoNormal"><i style="">documentation on the RSS version used by the channel.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><generator> Defines the automatic generator that indicates the program used to generate the channel.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><image> Inserts graphics in the channel.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><language> Specifies the language used by a channel. This element is used to group websites based on<o:p></o:p></i></p> <p class="MsoNormal"><i style="">the language used by RSS aggregators.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><lastBuildDate> Specifies the date on which a channel was last modified.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><managingEditor> Specifies the e-mail address of the editor of a website.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><pubDate> Specifies the publication date for the content in a channel.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><rating> Specifies the parental control rating of a Web page.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><skipDays> Specifies the number of days for which the feed is not updated.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><skipHours> Specifies the number of hours for which the feed is not updated.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><textInput> Creates a text input box that can be displayed with the channel.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><ttl> Specifies the minutes for which the channel remains cached without refreshing.<o:p></o:p></i></p> <p class="MsoNormal"><i style=""><webMaster> Specifies the e-mail address of the webmaster of a feed.<o:p></o:p></i></p> <p class="MsoNormal"><i style="">?? <Item>-Contains information, such as title, link, and description, which you intend to display on your </i>RSS feed. It enables a developer to provide links to the content (including the updated content) of a website.<o:p></o:p></p> <p class="MsoNormal">The <Item> element supports a number of attributes. These attributes were introduced with RSS 2.0, which provides greater flexibility to work with the files of earlier version of RSS, such as RSS 0.91 and RSS 1.0.<o:p></o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><b>Table B.3: Sub-Elements of the <item> Element<o:p></o:p></b></p> <p class="MsoNormal"><b>Element Description<o:p></o:p></b></p> <p class="MsoNormal"><author> Specifies the name of the author who has written the content included in an item<o:p></o:p></p> <p class="MsoNormal"><category> Specifies the category of a channel<o:p></o:p></p> <p class="MsoNormal"><comments> Contains the URL of the Web page that contains the comments related to an item<o:p></o:p></p> <p class="MsoNormal"><enclosure> Specifies the media object, such as mp3 files, that are enclosed with the content of an item<o:p></o:p></p> <p class="MsoNormal"><guid> Defines the Globally Unique Identifier (GUID), which is a unique value, for identifying an<o:p></o:p></p> <p class="MsoNormal">item<o:p></o:p></p> <p class="MsoNormal"><pubDate> Defines the last publication date for an item<o:p></o:p></p> <p class="MsoNormal"><source> Defines the third-party source used in an item<o:p></o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><b>Table B.3: Sub-Elements of the <item> Element<o:p></o:p></b></p> <p class="MsoNormal"><b>Element Description<o:p></o:p></b></p> <p class="MsoNormal"><title> Specifies the title of the item<o:p></o:p></p> <p class="MsoNormal">link Specifies the URL of the item<o:p></o:p></p> <p class="MsoNormal">description Specifies synopsis for an item<o:p></o:p></p> <p class="MsoNormal">Now, let s discuss the Atom feed.<o:p></o:p></p> <p class="MsoNormal">Atom Feed<o:p></o:p></p> <p class="MsoNormal">Atom is a format based on XML language that is used for Web feeds. It was developed by Internet Engineering<o:p></o:p></p> <p class="MsoNormal">Task Force (IETF) Working Group. IETF is a large community of designers and researchers concerned with<o:p></o:p></p> <p class="MsoNormal">Internet architecture and the smooth operation of Internet Explorer. Web syndication formats, such as RSS and<o:p></o:p></p> <p class="MsoNormal">Atom, are now used as an important tool to perform many tasks in various fields, such as marketing, news.<o:p></o:p></p> <p class="MsoNormal">Atom provides the user with the capability to export an entire blog or parts of a blog.<o:p></o:p></p> <p class="MsoNormal">The development of the Atom format has provided a useful alternative to the RSS format. Atom resolves certain<o:p></o:p></p> <p class="MsoNormal">ambiguities of RSS, such as RSS incapability to distinguish plain text or HyperText MarkUp Language (HTML),<o:p></o:p></p> <p class="MsoNormal">by providing the capability to unambiguously label the type of content. Moreover, the syntax of Atom is<o:p></o:p></p> <p class="MsoNormal">designed in such a way that it can be reused outside the context of an Atom feed document. For example, it is<o:p></o:p></p> <p class="MsoNormal">possible to find <atom:link> elements, which are used to define a reference from an entry or feed to a website,<o:p></o:p></p> <p class="MsoNormal">used within RSS 2.0 feeds. Here is the syntax of a sample Atom feed:<o:p></o:p></p> <p class="MsoNormal"><?xml version="1.0" encoding="utf-8"?><o:p></o:p></p> <p class="MsoNormal"><feed version="0.3" xmlns="http://www.w3.org/2005/Atom"><o:p></o:p></p> <p class="MsoNormal"><title>Sample Feed

2005-2-13T28:40:01Z

Henry Wilkins

urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6

demonstrating Atom Syntax

urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a

2003-12-13T18:30:02Z

descriptional text

 

In the preceding syntax, the first line is the XML declaration, which specifies the XML version of a document.

According to W3C, all Atom feed files must conform to the XML 1.0 specifications. Some elements and attributes

used in the preceding syntax are explained as follows:

 

?? -Acts as a container for metadata and associated data of the feed. This element is a top-level

element of an Atom feed document. Some noteworthy attributes of the element are:

. id-Identifies the feed with the help of a unique Uniform Resource Identifier (URI) and specifies a

globally unique identifier for the entry, which should not change over time.

. title-Specifies a readable and striking title for the feed. This name is usually the same as the title of

the associated website. The link may have a attribute, whose value must be a String.<o:p></o:p></p> <p class="MsoNormal">. updated-Specifies the time when the feed was last modified. It is the last updated timestamp.<o:p></o:p></p> <p class="MsoNormal">. category-Indicates the category to which the feed belongs.<o:p></o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><b><i>Implementing RSS and Atom Feed<o:p></o:p></i></b></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal">. contributor-Indicates a single contributor to the feed. Multiple contributor elements can also be<o:p></o:p></p> <p class="MsoNormal">provided in a feed.<o:p></o:p></p> <p class="MsoNormal">. generator-Specifies the software used for generating and debugging the feed.<o:p></o:p></p> <p class="MsoNormal">. icon-Provides an iconic visual identification in the form of a small image for the feed.<o:p></o:p></p> <p class="MsoNormal">. logo-Provides visual identification in the form of a large image (as compared to an icon element) for<o:p></o:p></p> <p class="MsoNormal">the feed.<o:p></o:p></p> <p class="MsoNormal">. rights-Provides information about rights, such as copyrights, in a feed.<o:p></o:p></p> <p class="MsoNormal">?? <entry>-Behaves similar to the <item> element in RSS. It has the following attributes:<o:p></o:p></p> <p class="MsoNormal">. id-Identifies an entry by using a universally unique and permanent URI.<o:p></o:p></p> <p class="MsoNormal">. title-Contains a title for an entry. This value should not be blank.<o:p></o:p></p> <p class="MsoNormal">. updated-Indicates the time when noteworthy changes were last made to an entry.<o:p></o:p></p> <p class="MsoNormal">. category-Indicates the category to which an entry belongs.<o:p></o:p></p> <p class="MsoNormal">. contributor-Indicates a single contributor to the entry.<o:p></o:p></p> <p class="MsoNormal">. published-Specifies the time when the entry is created.<o:p></o:p></p> <p class="MsoNormal">. source-Specifies that, if an entry is copied from one feed to another feed, then the child elements of<o:p></o:p></p> <p class="MsoNormal">the feed other than the <entry> elements should be preserved.<o:p></o:p></p> <p class="MsoNormal">. rights-Provides information about copyrights held over an entry.<o:p></o:p></p> <p class="MsoNormal">. content-Contains either the content or the links to the content for an entry.<o:p></o:p></p> <p class="MsoNormal">. summary-Contains an abstract of the data contained in an entry.<o:p></o:p></p> <p class="MsoNormal">After knowing about RSS and Atom feeds, let s learn how to create and use an RSS feed in a website.<o:p></o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><b style=""><u>Creating an RSS Feed<o:p></o:p></u></b></p> <p class="MsoNormal"><b style=""><u><o:p><span style="text-decoration: none;"> </span></o:p></u></b></p> <p class="MsoNormal">Perform the following steps to create an RSS feed for a website:<o:p></o:p></p> <p class="MsoNormal">1. Create a website and name it CreateRSSFeed<b>. </b>You can find this website as CreateRSSFeed (in C#) and<o:p></o:p></p> <p class="MsoNormal">CreateRSSFeedVB (in VB) in the CD-ROM.<o:p></o:p></p> <p class="MsoNormal">2. Now, create a new database named rsssample. Next, execute the following code, given in Listing B.1 of<o:p></o:p></p> <p class="MsoNormal">the SQL script (also available as SQLQuery1 in the CD-ROM):<o:p></o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><b>Listing B.1: </b><b style="">Showing the Code for rsssample Database<o:p></o:p></b></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal">CREATE TABLE [newsdata] (<o:p></o:p></p> <p class="MsoNormal">[newsid] [smallint] IDENTITY (1, 1) NOT NULL ,<o:p></o:p></p> <p class="MsoNormal">[newstitle] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,<o:p></o:p></p> <p class="MsoNormal">[newsdescription] [varchar] (5000) COLLATE SQL_Latin1_General_CP1_CI_AS<o:p></o:p></p> <p class="MsoNormal">NULL ,<o:p></o:p></p> <p class="MsoNormal">[newsauthor] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,<o:p></o:p></p> <p class="MsoNormal">[newsdate] [datetime] NULL ,<o:p></o:p></p> <p class="MsoNormal">PRIMARY KEY CLUSTERED<o:p></o:p></p> <p class="MsoNormal">(<o:p></o:p></p> <p class="MsoNormal">[newsid]<o:p></o:p></p> <p class="MsoNormal">) ON [PRIMARY]<o:p></o:p></p> <p class="MsoNormal">) ON [PRIMARY]<o:p></o:p></p> <p class="MsoNormal">GO<o:p></o:p></p> <p class="MsoNormal">3. Now, create a table named as newsdata in the rsssample. Specify values for all fields in the table.<o:p></o:p></p> <p class="MsoNormal">4. After creating the newsdata table, insert some records to create an RSS feed. Now, replace the code for the<o:p></o:p></p> <p class="MsoNormal">Default.aspx file of the CreateRSSFeed website with the following code to add the controls required<o:p></o:p></p> <p class="MsoNormal">for the CreateRSSFeed website. You can find the code for the Default.aspx page in Listing B.2:<o:p></o:p></p> <p class="MsoNormal"><o:p> </o:p></p> <p class="MsoNormal"><u><span style="">Listing B.2: </span>Showing the Code for the Default.aspx Page<o:p></o:p></u></p> <p class="MsoNormal"><u><o:p><span style="text-decoration: none;"> </span></o:p></u></p> <p class="MsoNormal"><b style=""><i>In VB<o:p></o:p></i></b></p> <p class="MsoNormal"><i style=""><%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb"<o:p></o:p></i></p> <p class="MsoNormal"><i style="">Inherits="_Default" %><o:p></o:p></i></p> <p class="MsoNormal"><i style=""><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"<o:p></o:p></i></p> <p class="MsoNormal"><i style="">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><o:p></o:p></i></p> <p class="MsoNormal"><i style=""><html xmlns="http://www.w3.org/1999/xhtml"><o:p></o:p></i></p> <p class="MsoNormal"><i style=""><head id="Head1" runat="server"><o:p></o:p></i></p> <p class="MsoNormal"><i style=""><title>Creating RSS Feed


 

In C#

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"

Inherits="_Default" %>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Creating RSS Feed


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend