Geeks With Blogs
Path Notes of a Kodefu Master blog

Reading in a series of blog posts is made easy utilizing classes that came in the .NET Framework 3.5. As long as the feed is in the Atom 1.0 or RSS 2.0 formats, you easily build your own aggregator service.

SyndicationFeed feed = null;
using (XmlReader reader = XmlReader.Create(feedUrl))
{
    feed = SyndicationFeed.Load(reader);
}
foreach (SyndicationItem item in feed.Items)
{
}

Off of the item, you will probably want to grab the Title.Text and the Summary.Text. Be sure to HtmlDecode them! Another important thing is the Categories collection, which I’m using as tags. Here’s the line of code from my project: Tags = item.Categories.Select(c => c.Name).Aggregate((a, b) => a + "," + b).

Lastly, an aggregator would be pointless unless you were grabbing the url (get it from Links[0].Uri.ToString()). However, many feeds are using Feedburner. If you pull from feedburner, the url will be a feedproxy.google.com url instead of one that goes directly to the blog article. The trick to get around this turned out to be quite simple. Make a WebRequest to the feedproxy url then read the WebResponse’s url.

private static string GetTrueUrl(string url)
{
    if (url.StartsWith("http://feedproxy.google.com"))
    {
        var request = WebRequest.Create(url);
        using (var response = request.GetResponse())
        {
            url = response.ResponseUri.ToString();
            response.Close();
        }
    }
    return url;
}
That’s all there is to reading in standard feeds. I’ll leave it up to you to decide on a specific implementation.Note: Cross posted from KodefuGuru.
Permalink
Posted on Tuesday, September 8, 2009 3:06 PM | Back to top


Comments on this post: SyndicationFeed and Beating FeedProxy

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Chris Eargle | Powered by: GeeksWithBlogs.net