9.1. Putting an RSS Feed on a Page

RSS is a format for an XML document that describes a list of items, such as blog entries or news headlines. The document may just be a stream of XML created on the fly rather than a static file. In this section, you put an RSS document (using Version 2.0) on a page by using the XmlDataSource and DataList controls.

9.1.1. Analyzing an RSS feed

RSS Version 2.0 presents a hierarchy of nodes. A stripped-down RSS structure looks like this:

<rss>
    <channel>
       <item>
           <title></title>
           <description></description>
           <link></link>
           <pubDate></pubDate>
           <!--...-->
        </item>
     </channel>
</rss>

To retrieve text within a <title> element, you need to stroll through <rss>, <channel>, and <item>. In XML, you can describe the route to the <title> text by using XPath syntax. As you see in the next section, the ASP.NET XmlDataSource control does the strolling for you.

9.1.2. Using the XmlDataSource control

The XmlDataSource control has an XPath property that bores into an XML document to make finding the data you want easy. Follow these steps to point an XmlDataSource to an RSS feed:

  1. From the Toolbox, add an XmlDataSource control to an ASP.NET page.

  2. From the XmlDataSource Tasks menu (click the Smart Tag button), select Configure Data Source.

  3. In the Data file text box, enter the URL for the RSS feed.

    For example:

    http://www.microsoft.com/presspass/rss/TopStory.xml

    NOTE

    The URL may use extensions such as .aspx, .php, and so on. What's important is that the location produces an ...

Get ASP.NET 3.5 For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.