Reading Multiple Feed Formats

Topics: Argotic.Core
Jan 8, 2008 at 4:02 AM
I have been using Argotic Syndication Framework in a web application that reads and displays feeds from various sources. It's great to have a single tool that will handle both Atom and RSS feeds. Thank you!

When reading these feeds, I don't know beforehand which format a feed will be in. Therefore, I'm trying to read as an Atom feed, then if that throws a FeedFormat exception, I read it as an RSS feed. This works, however, it makes two web calls when reading RSS feeds. Here is the code I'm using:

try
{
AtomFeed feed = new AtomFeed();
feed.Load(this.FeedURL);
OutputAtomFeed(feed);
}
catch (FormatException)
{
try
{
RssFeed feed = new RssFeed();
feed.Load(this.FeedURL);
OutputRssFeed(feed);
}
catch (FormatException)
{
this.Controls.Add(new LiteralControl("<p>Unknown Feed Format</p>"));
}
catch (Exception e2)
{
this.Controls.Add(new LiteralControl("<p>" + e2.Message + "</p>"));
}
}
catch (Exception e)
{
this.Controls.Add(new LiteralControl("<p>" + e.Message + "</p>"));
}

Is there a good way to read either format of feed without ever having to make the second web call?
Coordinator
Jan 8, 2008 at 5:56 AM
See the GenericFeed and GenericFeedItem classes in the Argotic.Core namespace, these are designed for format agnostic reading of syndication feeds.