ASP.Net: Consuming RSS Feeds MK II

by matt 12. June 2009 15:51

Bah, I just found a much quicker and much simpler way of reading RSS while reading Mats Hellström’s blog article about Aggregating Feeds on the EPiServer Blogs.

Mats is talking about taking multiple feeds and adding them together, I’m still really only interested in on.  The key point I took from his blog is the SyndicationFeed class and all of its pals from the System.ServiceModel.Syndication namespace.  This makes most (read that as all) of my previous post on the subject pretty much irrelevant, as this is all nicely handled for us.

The code blow shows how I might do somethign similar to the previous post using nicer code:

using System;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Xml;
 
namespace Using_Syndication_Feed
{
    class Program
    {
        static void Main(string[] args)
        {
            SyndicationFeed rssFeed = SyndicationFeed.Load(
                    XmlReader.Create("http://www.planet-f1.com/rss/0,16039,3213,00.xml")
                    );
 
            Console.WriteLine(
                String.Format(
                    "{0} > {1}",
                    rssFeed.Title.Text,
                    rssFeed.Links[0].Uri.AbsoluteUri
                    )
                );
 
            foreach (SyndicationItem rssItem in rssFeed.Items.Take(10))
            {
                Console.WriteLine(
                    String.Format(
                        "{0} - [{1}]",
                        rssItem.Title.Text,
                        rssItem.PublishDate.ToString("s")
                        )
                    );
            }
 
            Console.ReadLine();
        }
    }
}

Tags:

ASP.NET

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar