devxlogo

Learn to Consume RSS Using DevX’s New Content Feeds

Learn to Consume RSS Using DevX’s New Content Feeds

SS (Really Simple Syndication) feeds are an easy way for organizations to distribute content. At the most basic level, an RSS feed, or channel, is an XML document containing a list of titles, descriptions, and links to content. Any client that can parse XML can read and format the content to display the titles, descriptions, and links in a custom context, such as within a

tag on a Web page or on a Windows form.

To use an RSS feed, you need to:

Create the context.
Decide what you want to do with the feed and how you want it to look.

Retrieve the XML feed.
All you need is the URL for the feed location. Then you make a standard HTTP GET request for the XML data. You can treat the result as a file, writing it to local storage, or as transient in-memory data.

Parse and format the results.
To display the contents, you need to parse the XML document, extracting and formatting the information you want to display. The simplest way to do that is to use an XSLT stylesheet to control the display characteristics.

Editor’s Note: If you’re interested in using the DevX content feeds either individually or on a Web site, visit our RSS FAQ page.

RSS 2.0 Document Structure

Figure 1. Viewing the XML: In the sample application, you can hit the “Show RSS Document” button to invoke the getXMLFeed method, which displays the raw XML.

RSS has gone through three versions since its inception. DevX’s feeds adhere to the latest specification, RSS 2.0.

Let’s begin by running through the basic structure of a feed. An RSS 2.0 document must begin with the standard XML declaration containing version and encoding attributes.

The next tag is an element containing a single child element. The element must contain title, link, and description elements. These typically contain the title of the feed source organization, a link to that organization, and a description of the feed contents. For example, DevX’s element looks like this:

    DevX: Latest Published Articles    http://www.devx.com    Latest DevX Content    ... 

In addition to the three required elements, the element may contain a number of optional elements;. DevX uses these additional elements:

    en-us    Copyright 2002 DevX    http://backend.userland.com/rss    Wed, 18 Jun 2003         23:30:51 PST           DevX                   http://services.devx.com/outgoing/devxwire.gif              http://www.DevX.com    

The optional elements , , and are mostly self-explanatory. The element tells you the source of the feed while the element is used in our case to display the DevX logo.

The element is documentation for the RSS version and usually links to the Radio UserLand RSS page as shown. The element is particularly important for automation purposes. Some organizations, such as those with stock market feeds, update their RSS feeds often; others, such as DevX, update the feeds on a daily basis, or only when information changes. If you’re caching feeds information locally, you only need to update the cache when the value of the element changes.

The element also contains a list of elements. These are the individual pieces of content. All child elements are optional, but each must contain, at minimum, a </span> or a <span class="pf"><description></span> element. In practice, most <span class="pf"><item></span> elements contain a title, a link, and a description. Again, the RSS 2.0 specification lists <a href=" http://backend.userland.com/rss#hrelementsOfLtitemgt " target = "_blank">optional <span class="pf"><item></span> elements</a>. DevX uses the following <span class="pf"><item></span> structure.</p> <p><pre><code><item> <title>Title here Description URL Author(s) names Thu, 12 Jun 2003 13:23:27 PST

Obtaining a DevX RSS Feed with .NET
Obtaining the content of a DevX RSS feed (or performing any HTTP GET request) with .NET is straightforward. You simply add a reference to the System.Net namespace to your class or module.

Imports System.Net

After doing that, you can use the WebClient object in the System.Net namespace to make requests to a URL and retrieve the results. The following getXMLFeed method uses a WebClient to request the XML data. The method might just as easily be called “DoHTMLGetRequest,” because it isn’t specific to XML nor to RSS feeds?it just makes a GET request and returns the result.

   Public Function getXMLFeed( _      ByVal URL As String) As String      Dim wc As New WebClient      Dim b() As Byte      Dim sXML As String = String.Empty      b = wc.DownloadData(URL)      sXML = System.Text.Encoding.ASCII.GetString(b)      Return sXML   End Function

The sample application in this article (and in the downloadable source code, left) obtains the RSS documents from DevX using the getXMLFeed method.

Transforming the RSS Feed to HTML
Now that you’ve obtained the RSS document, you need to write the instructions to display the contents. There are a number of sites on the Web that will perform RSS-to-HTML transformations for you, and DevX exposes the feeds as HTML directly, in a form suitable for inclusion in an