By Scott Mitchell
Introduction
Websites that produce new content on a regular basis should include a syndication feed, which is a specially formatted XML file that includes a summary of the most recently published items. Virtually all blogs, news sites, and social media sites have a syndication feed, and 4Guys is no exception. The 4GuysFromRolla.com syndication feed contains the most recent articles. Syndication feeds are meant to be consumed by computers. Sites like Technorati parse the syndication feeds from blogs and use that data to determine the topic du jour. Also, syndication feeds are commonly used by websites to display the latest headlines from related sites. For example, an ASP.NET community website could consume the 4GuysFromRolla.com syndication feed to display the latest 4Guys headlines.
Until recently, there was no built-in support for creating or consuming syndication feeds in the .NET Framework. That changed with the release of the .NET Framework version 3.5, which included a new namespace: System.ServiceModel.Syndication. This new namespace includes a handful of classes for working with syndication feeds. As aforementioned, syndication feeds are XML files, and for the syndication feed to be of any use it must conform to one of the popular syndication feed standards. The two most popular syndication feed standards are RSS 2.0 and Atom 1.0, and these are the standards supported by the classes in the System.ServiceModel.Syndication namespace. But there is a third format that, while not as popular as RSS 2.0 or Atom 1.0, is still used. That standard is RSS 1.0.
The good news is that with a little bit of work we can create a class that works with the RSS 1.0 standard and have this class used by the syndication feed-related classes in the .NET Framework 3.5 can be. This article introduces a free library, skmFeedFormatters, which you can use in an ASP.NET 3.5 application to create and consume RSS 1.0 feeds. (This same concept could be applied to creating and parsing Atom 0.3 feeds, as well.)
Brief History of Syndication Feed Standards
The idea of online syndication feeds was first proposed by Dave Winer back in 1997 as a way for exposing the content of his blog in a machine-readable format. Dave called his standard RSS for Really Simple Syndication. Over the years he continued fine tuning the standard until 2003, at which point the standard was frozen with the release of RSS 2.0. RSS 2.0 is a very popular syndication feed standard in large part because it is very simple and straightforward, making it easy to implement and parse. For example, the 4Guys syndication feed adheres to the RSS 2.0 standard.
Around the same time a group from Netscape set about crafting a syndication standard based on Resource Description Framework (RDF), a standard proposed by the W3C for representing information about resources on the web. To make things as confusing as possible, this new syndication feed standard was named RDF Site Summary, or RSS for short, resulting in two differing standards with the same acronym! Eventually, this work by Netscape (and later O'Reilly) became known as RSS 1.0 and Dave's standard as RSS 2.0, although sometimes the RSS 1.0 standard is referred to as RDF to help remove any ambiguity.
After the RSS 2.0 standard was frozen in 2003, Sam Ruby proposed a new standard to overcome RSS 2.0's shortcomings. This new standard was defined by the community and named Atom. The first major release was Atom 0.3. After some more changes, the final, standardized version was released as Atom 1.0. (Unfortunately, some sites still syndicate content using the Atom 0.3 standard.)
The two most widely used standards are RSS 2.0 and Atom 1.0. However, some sites still use RSS 1.0 or Atom 0.3. For example, the popular tech news and discussion site Slashdot.org syndicates its content using RSS 1.0.
Creating and Consuming Syndication Feeds in ASP.NET 3.5
The .NET Framework version 3.5 introduced a new namespace, System.ServiceModel.Syndication, with a number of classes for creating and consuming syndication feeds. These classes are divided into two categories: classes that model a syndication feed and the items in a feed, and classes that are responsible for transforming the classes that model syndication feeds into the appropriate XML and vice-a-versa.
Classes That Model Syndication Feeds and Items
SyndicationFeed - represents a syndication feed. Has properties like Title, Description, Links, and Items. The Items property represents the collection of content items expressed in the feed.
SyndicationItem - represents a specific syndication feed item and includes properties like Title, Summary, PublishDate, Authors, and so on.
Classes That Transform Syndication Feeds To/From XML
Rss20FeedFormatter - can take a SyndicationFeed object and turn it into XML that conforms to the RSS 2.0 specification. Also, can be used to consume a properly-formatted RSS 2.0 feed, turning the XML into a SyndicationFeed object with its properties set based on the data in the consumed XML.
Atom10FeedFormatter - same as the Rss20FeedFormatter, but uses the Atom 1.0 standard.
The .NET Framework 3.5 only ships with two feed formatter classes for the RSS 2.0 and Atom 1.0 specifications. Consequently, you cannot syndicate or consume RSS 1.0 or Atom 0.3 feeds out of the box. In his blog entry How to upgrade Atom 0.3 feeds on the fly with a custom XmlReader for use with WCF Syndication APIs, Daniel Cazzulino shows how you can use XSLT to transform Atom 0.3 markup to Atom 1.0-compliant markup on the fly.
A more formal approach, in my opinion, is to create your own feed formatter class. The Rss20FeedFormatter and Atom10FeedFormatter classes in the System.ServiceModel.Syndication namespace derive from the base class SyndicationFeedFormatter. We can create our own formatter class by extending this base class. For example, we could create an Atom03FeedFormatter class and use it to turn a SyndicationFeed object into conforming XML, or consume an Atom 0.3 XML feed and generate a corresponding SyndicationFeed object.
The download available for download at the end of this article includes a class named Rss10FeedFormatter, which can be used to create and consume RSS 1.0 feeds. The download also includes a demo website showing this class in action. The remainder of this article explores the Rss10FeedFormatter class. (You could take the concepts presented in this article to create an Atom03FeedFormatter class, or a class to work with other, more esoteric feed formats, should the need arise.)
Tuesday, April 7, 2009
Subscribe to:
Post Comments (Atom)

1 comments:
test
Post a Comment