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();
}
}
}
9d3f3399-e0a5-4cc9-a146-bb38ad9bf38d|0|.0
Tags:
ASP.NET