Create an RSS Feed for your Website

Wednesday, January 25, 2012

rss icon

RSS, also commonly known as Really Simple Syndication, is a feed format used to publish frequently updated content from sources such as blog entries, news headlines, and other standardized formats. An RSS feed or channel can include a full or summarized portion of the entry as well as other metadata. RSS feeds benefit publishers by letting them syndicate content automatically. Using a standardized XML file format, the feed allows the information to be published once and viewed by many different programs, or readers. Those who are interested in your content as well as other feeds on the Internet can do so in one place. RSS feeds can be read using software known as an "RSS reader", "feed reader", or "aggregator", which can be web-based, desktop-based, or mobile-device-based. The user subscribes to a feed by entering into the reader the feed's URI or by clicking a feed icon in a web browser that initiates the subscription process. The RSS reader checks the user's subscribed feeds regularly for new content, downloads any updates that it finds, and provides a user interface to monitor and read the feeds. RSS allows users to avoid manually inspecting all of the websites they are interested in, and instead subscribe to websites such that all new content is pushed onto their readers when it becomes available.

How to produce an RSS Feed

Unless you are maintaining a website or want to create your own RSS feed, there's not much work involved. This is especially true if you have a blog site on a hosted service such as Blogger or Wordpress. Both of those blogging sites automatically provide you with a feed address so that you can make it available to your users, without having to programmatically create your own feed. If you have your own website, you have a few options for publishing your own RSS feed. In its most basic form, RSS is presented by way of an XML file. Most feeds found on websites and blogs are maintained using special "content management" software.  If you prefer not to purchase pre-developed software to publish your feed, you can publish your own feed by creating an XML file manually. Here is an example of the structure of an RSS feed (not all of the tags are required...see example below)

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
        <title>RSS Title</title>
        <description>This is an example of an RSS feed</description>
        <lastBuildDate>Wed, 25 Jan 2011 00:01:00 +0000 </lastBuildDate>
        <pubDate>Wed, 25 Jan 2011 00:01:00 +0000 </pubDate>
                <title>Entry #1</title>
                <description>Here is some text containing a description.</description>
                <guid>unique string, usually same as link</guid>
                <pubDate>Wed, 25 Jan 2011 00:01:00 </pubDate>

Of course, manually updating this file by hand can be quite workload intensive, not to mention, the risk of errors due to human intervention. Alternatively, you can leverage server scripting such as in the case of to build the rss feed at run time (whenever the feed is requested from your site). The following code listed below is an example of an page which will produce an RSS feed from a database source. To build this feed, create a blank aspx page and use the code listed below in your code-behind page (aspx.vb).

Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Web
Imports System.Xml

Partial Class RSS
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.ContentType = "text/xml"

        Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        objX.WriteAttributeString("version", "2.0")
        objX.WriteElementString("title", "My RSS Feed")
        objX.WriteElementString("link", "")
        objX.WriteElementString("description", "The latest headlines and articles from the world of mysite.")
        objX.WriteElementString("copyright", "(c) 2011, All rights reserved.")
        objX.WriteElementString("ttl", "5")

        Dim ConnrssDetails As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection_
        Dim CommandrssDetails As New System.Data.SqlClient.SqlCommand
        Dim ReaderrssDetails As System.Data.IDataReader

        CommandrssDetails.Connection = ConnrssDetails
        CommandrssDetails.CommandText = "SELECT Top 20 ARTICLEID, Title, Description, PublishDate from TABLE1"

        ReaderrssDetails = CommandrssDetails.ExecuteReader()

        While ReaderrssDetails.Read()
            objX.WriteElementString("title", ReaderrssDetails.GetString(1))
            objX.WriteElementString("description", ReaderrssDetails.GetString(2))
            objX.WriteElementString("link", "" + ReaderrssDetails.GetString(0))
            objX.WriteElementString("pubDate", ReaderrssDetails.GetDateTime(3).ToString("R"))
        End While


    End Sub
End Class

After you have successfully built your feed source, you can use this online feed validator to ensure that your feed is formatted properly: The final step is to publish a link on your website so that users can find your feed. Once your feed is up and functional, you may want to take a look at some other services on line that help you manage your feed such as Google's FeedBurner. Not only can users subscribe to your feed using this service, they can subscribe using various readers including an email subscription service. Feedburner also collects information about your feed and allows you to monitor your feed's health.

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

Internet World Wide Web: How to Program How to Host Your Own Web Server