Steve Smith's Blog

Musings on Software and the Developer Community

Getting RSS Right

Just made some updates to the aggregate RSS feed on DevMavens.com so that it's more correct.  We weren't displaying the author correctly before (and we're still not complying with the RFC that wants <author /> to contain an email address, but I see no reason to increase the spam these folks get as it is).  I also noticed that our dates weren't formatted correctly, though I had thought originally they were.  Here's the code we had:

<pubDate><%= rssItem.DatePublished.ToUniversalTime() %></pubDate>

Can you spot the problem?

Turns out that even after converting to UniversalTime you still need to format it correctly, which in this case means using  the "R" format string:

<pubDate><%= rssItem.DatePublished.ToUniversalTime().ToString("R") %></pubDate>

And with that, the feed appears to be working correctly.  Hopefully FeedBurner will pick it up soon.  Related to this, I've been looking at replacing my existing RSS library with the Argotic syndication project, but it is lacking a few features that I need.  I'm talking with the project coordinator now and we'll see if the things I need can easily be added.  My primary need is the ability to merge several feeds into one, purging any duplicates and truncating the result while maintaining sort order by pubDate.  I have routines that do all of these things (with tests!) that I'll gladly add to the Argotic project.  Then I think the only other thing that I use now (which I could easily add via subclassing if necessary) is a property on RssItem called AssociatedObjectKey that allows me to link individual RssItems with their author, owner, blog, etc. in a strongly typed fashion.  I might be able to use the Enclosure support in Argotic to achieve this - I haven't had a chance to check that out yet.

In terms of ease of use, the simple case of consuming and displaying a single feed with Argotic is pretty straightforward.  Something like this works great:

RssFeed feed = RssFeed.Create(new Uri(http://feeds.SteveSmithBlog.com/StevenSmith));
Console.WriteLine(feed.Channel.Description);
foreach (RssItem item in feed.Channel.Items)
{
  Console.WriteLine(item.Author + " wrote " + item.Title);
}


The nice thing about this is that it doesn't matter what format or extensions are in use by the feed (as long as it's one of the many supported formats), so whether it's RSS or ATOM or even BlogML, it should work.

    kick it on DotNetKicks.com

Tuesday, 08 July 2008

Comments

 avatar

G. Andrew Duthie said on 08 Jul 2008 at 1:21 PM

Argotic works great. I use it for the main feed on CommunityMegaphone.com, and it made adding GeoRSS support, as well as .ics enclosures for adding events to Outlook, much easier.

Regarding the <author> element, have you considered using the DublinCore <creator> element instead? It's more flexible than the RSS <author> element in terms of content, so you can provide a name instead of email address, and the feed will still validate. I've got code for Argotic I can send you if you like.


 avatar

Tony Harrison said on 29 Aug 2008 at 8:14 AM

I am curious how did you add geoRSS support to Argotic?


 avatar

G. Andrew Duthie said on 02 Sep 2008 at 2:09 PM

Basic Geocoding is supported via a built-in extension to Argotic, and can be accomplished in 4 lines of code:

Dim itemExtension As New _

BasicGeocodingSyndicationExtension()

itemExtension.Context.Longitude = Longitude

itemExtension.Context.Latitude = Latitude

item.AddExtension(itemExtension)

This adds <geo:lat> and <geo:long> elements to the RSS feed, which is then consumable by any app or reader that understands the basic GeoRSS format, including the Virtual Earth map control, Windows Live Search for Mobile, etc.