Argotic Syndication Framework in use

Since the Argotic Syndication framework played a large part in my masters dissertation and will play a part in the desktop based RSS reader, I’ve devoted this post to it. As mentioned before you can find out more about the framework from here. Code snippets are shown in C#.

This section will cover the core set of features provided by the framework and incorporated into the RSS reader application. The fragments of code in C# shown only concentrate on RSS for the purpose of giving a reader an insight into the code used in the application.

Feature: Creating an RSS feed object

To create an RSS object the Create method is called with a parameter containing the http location of the specific feed, this in turn returns an RssFeed object to work with.

using Argotic.Syndication;
Uri loc= new Uri(“http://news.google.co.uk/nwshp?hl=en&tab=wn&output=rss”);
RssFeed feed = RssFeed.Create(loc);

Feature: Exploring RSS Items in a RSS feed The RssFeed object created had all the elements which were described in the RSS specification

The example below demonstrates a loop which iterates through the items found in the RSS feed using the framework.

using Argotic.Syndication;
Uri loc = new Uri
(“http://news.google.co.uk/nwshp?hl=en&tab=wn&output=rss”);
RssFeed feed = RssFeed.create(loc);
foreach(RssItem item in feed.Channel.Items)
{
  String title = item.Title;        //RSS item Title
  String desc = item.Description;  //RSS item Description
  String auth = item.Author;       //RSS item Author
  String guid = item.Guid;  //RSS item Guid
  String link = item.Link.toString(); //RSS item Link
}

Feature: Extracting extensions from an item (Syndication Extensions)

Syndication Extensions allow additional meta-data to be added to a feed. So for example if you see flash objects, movie files, audio files attached in a feed then syndication extensions are incorporated.

Below is a fragment of C# code checking to see whether a particular item in an RSS feed has an iTunes syndication extension (podcast episode) attached and if so essential elements are then extracted from the specific item namely; author, duration, subtitle and summary.

using Argotic.Syndication;
using Argotic.Extensions.Core;

Uri loc = new Uri(“http://news.google.co.uk/nwshp?hl=en&tab=wn&output=rss”);
RssFeed feed = RssFeed.create(loc);
foreach(RssItem item in feed.Channel.Items)
if(item.HasExtensions)
{
  ITunesSyndicationExtension itunesExtension= item.FindExtension
    (ITunesSyndicationExtension.MatchByType)  ITunesSyndicationExtension;

  if(itunesExtension != null) //true if podcast found
  {
    String author = itunes.Context.Author;
    TimeSpan duration = itunes.Context.Duration;
    String subtitle = itunes.Context.Subtitle;
    String summary = itunes.Context.Summary
  }
 }
}

Feature: Creating an RssFeed

Another feature provided by the framework allows a developer to generate RSS feeds.Instead of reading in data, this part of the code involved setting data. Below is a snippet of code which invokes the feed generation feature in the framework. An RssItem object is created and later added to the channel of the RssFeed object.

using Argotic.Syndication;
RssFeed feed = new RssFeed();
feed.Channel.Link = new Uri(“http://tempuri.com”);
feed.Channel.Title = “Example feed”;
feed.Channel.Description = “Sample feed”;

RssItem item = new RssItem();
item.Title = “item title”;
item.Link = new Uri(“http://tempuri.com/feed/syndication”);
item.Description = “item description”;
feed.Channel.AddItem(item);
Last updated on 8 Jan 2009
Published on 8 Jan 2009