How to consume syndication feeds in a format agnostic manner

Published syndicated content can sometimes change its underlying content format while retaining the same URL endpoint. This can lead to scenarios where a consumer can not reliably predict the syndication format they will be consuming. The framework provides support for this type of scenario by allow you to consume syndication feeds in a format agnostic manner. This means that you can retrieve some general information about a syndication feed, the format it conforms to, and and its content items; and then cast the format agnostic view of the syndicated content to a strongly-typed representation of the published data.

The classes and enumerations that together compose the implementation of format agnostic feed consumption are located in the Argotic.Syndication namespace. The primary framework entity that you will use when working with a format agnostic view of syndication resources is the GenericSyndicationFeed class. This format agnostic view of a syndication feed exposes an Items collection of GenericSyndicationItem objects that provides an agnostic view of the discrete content for the syndication feed, while the GenericSyndicationCategory class represents the categorizations that have been applied to a feed or the feed's items.

Syndication feed abstraction API overview

The GenericSyndicationFeed class exposes the following properties:
  • Categories - A collection of GenericSyndicationCategory objects that represent the categories associated with the feed.
  • Description - Character data that provides a human-readable characterization or summary of the feed.
  • Format - The SyndicationContentFormat enumeration value that indicates the type of syndication format that the syndication feed conforms to.
  • Items - A collection of GenericSyndicationItem objects that represent distinct content published in the feed.
  • Language - A CultureInfo object that represents the natural or formal language in which the feed's content is written.
  • LastUpdatedOn - A DateTime object that represents a date-time indicating the most recent instant in time when the feed was modified in a way the publisher considers significant.
  • Resource - An object that implements the ISyndicationResource interface that represents the actual syndication feed that is being abstracted by the generic feed.
  • Title - Character data that provides the name of the feed.

The GenericSyndicationItem class exposes the following properties:
  • Categories - A collection of GenericSyndicationCategory objects that represent the categories associated with the item.
  • PublishedOn - A DateTime object that represents a date-time indicating an instant in time associated with an event early in the life cycle of the item.
  • Summary - A short summary, abstract, or excerpt for the item.
  • Title - The human-readable title for the item.

The GenericSyndicationCategory class exposes the following properties:
  • Scheme - A string that identifies the categorization scheme used by the category.
  • Term - A string that identifies the category.

Consuming syndicated content without prior knowledge of the format it conforms to

using Argotic.Common;
using Argotic.Syndication;

GenericSyndicationFeed feed     = GenericSyndicationFeed.Create(new Uri("http://www.pwop.com/feed.aspx?show=dotnetrocks&filetype=master"));

SyndicationContentFormat format = feed.Format;
string name                     = feed.Title;
string description              = feed.Description;
CultureInfo language            = feed.Language;
DateTime lastUpdatedOn          = feed.LastUpdatedOn;

foreach(GenericSyndicationCategory category in feed.Categories)
{
    string term     = category.Term;
    string scheme   = category.Scheme;
}

foreach (GenericSyndicationItem item in feed.Items)
{
    string title            = item.Title;
    string summary          = item.Summary;
    DateTime publishedOn    = item.PublishedOn;
    
    foreach (GenericSyndicationCategory category in feed.Categories)
    {
        string itemCategoryTerm     = category.Term;
        string itemCategoryTScheme  = category.Scheme;
    }
}

if (feed.Format == SyndicationContentFormat.Rss)
{
    RssFeed rssFeed = feed.Resource as RssFeed;
    if (rssFeed != null)
    {
        // Process format specific information
    }
}

Last edited Mar 3, 2008 at 5:26 PM by Oppositional, version 2

Comments

stopthatastronaut Feb 22, 2010 at 12:05 PM 
No property for link? deliberate decision due to RSS having single links and Atom supporting multiple?