You can create your own RSS aggregator application in ASP.NET with a couple of pages and an XSLT style sheet. A example is shown in the following illustration which is accessible through the associated link.
RSS Aggregator
The Frameset Page
This aggregator uses frames for displaying three pages. The left frame contains a menu of links to RSS feeds; the top-right frame displays item title and description information from the chosen RSS file; the bottom-right frame displays the Web page to which the items link. The frameset page that organizes the browser window in this fashion is shown below.
<html> <head> <title>RSS Aggregator</title> </head> <frameset cols="22%,78%"> <frame name="FeedsFrame" src="Feeds.aspx"/> <frameset rows="35%,65%"> <frame name="ItemsFrame"/> <frame name="PageFrame"/> </frameset> </frameset>
The Feeds.aspx Page
When the frameset is opened the Feeds.aspx page is opened in the left frame. This page contains a set of <asp:HyperLink> controls, each of which opens the Items.aspx page (see below) in the top-right frame to display <item> nodes from the linked RSS file.
<html> <head> <title>Feeds</title> </head> <body> <form runat="server"> <div style="font-weight:bold; background-color:#663300; color:white; padding:5px"> RSS Feeds </div> <br/> <asp:HyperLink runat="server" NavigateURL="Items.aspx?URL=http://msdn.microsoft.com/rss.xml" Target="ItemsFrame" Text="MSDN Just Published" Style="font-size:9pt"/><br/> <asp:HyperLink runat="server" NavigateURL="Items.aspx?URL=http://msdn.microsoft.com/xml/rss.xml" Target="ItemsFrame" Text="XML Development Center" Style="font-size:9pt"/><br/> ... </form> </body> </html>
Notice that the NavigateURL property of the controls opens the Items.aspx page, passing along a query string coded with the URL of the RSS feed. This URL is taken from the RSS feed published on the Web site.
For this example the <asp:HyperLink> controls are hard coded on the page. An alternative would be to maintain feed links in a database and to generate the controls in script as the page is loaded. An advantage of doing this is that you could then provide scripts to update the database with added and deleted links. For present purposes, though, this hard-coding method is sufficient.
The Items.aspx Page
Links from the Feeds.aspx page open the Items.aspx page in the top-right frame. As this page opens it receives a query string giving the URL of the associated RSS feed. This XML file has an XSLT style sheet applied in order to produce a formatted display of item titles and descriptions.
<%@ Import Namespace="System.Xml" %> <%@ Import Namespace="System.Xml.Xsl" %> <SCRIPT runat="server"> Sub Page_Load If Request.QueryString("URL") <> "" Then Dim RSSFeed = New XmlDocument() RSSFeed.Load(Request.QueryString("URL")) RSSItems.Document = RSSFeed RSSItems.TransformSource = "Items.xsl" End If End Sub </SCRIPT> <html> <head> <title>Items</title> </head> <body> <form runat="server"> <asp:xml id="RSSItems" runat="server"/> </form> </body> </html>
As has been done previously, the XML file is loaded into a DOM document using the passed URL to point to the source file. The Items.xsl style sheet is applied by setting Document and TransformSource properties for the <asp:xml> control embedded on the page. This style sheet is shown below.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/rss/channel"> <div style="font-weight:bold; background-color:#663300; color:white; padding:5px"> <xsl:value-of select="title"/> </div><br/> <xsl:for-each select="item"> <a><xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute> <xsl:attribute name="target">DetailsFrame</xsl:attribute> <xsl:value-of select="title"/> </a> <div style="margin-left:20px; font-size:9pt"> <xsl:value-of select="description"/> </div> </xsl:for-each> </xsl:template> </xsl:stylesheet>
An <a href> link is made from the <link> node for each <item> in the file. This is done by coding an <a> tag for which href and target attributes are assigned through the <xsl:attribute> element. The target for the link is the bottom-right frame (DetailsFrame) of the frameset. In addition, the content of the <description> node is displayed.
A click on a formatted link, then, opens the associated page in the targeted bottom-right frame. Since all RSS links are to live content drawn from the sites, new RSS files are retrieved on each click in the menu, ensuring that the most recent news always is available.