Among some of the new classes introduced in Version 3.5 of the .NET Framework Class Library (FCL) were the syndication-related classes. While other technologies such as LINQ, extension methods and lambda expressions have been grabbing most of the attention the new syndication classes also deserve a nod. Part of the System.ServiceModel.Syndication namespace the classes offer a variety of methods to easily generate or consume syndication feeds in RSS 2.0 or ATOM 1.0 formats.
It's not that reading or writing feeds were exceedingly difficult before. FCL comes with a number of XML classes that facilitate working with XML data which all syndication feeds emanate from. No doubt there are plenty of sample code out there that made the task as easy as copy, paste and tweak. But now FCL comes with its own native classes to handle feeds, with advanced settings, intellisense, and potential of extension.
To demonstrate ease of use, here's a sample code that pulls in a sample feed from Google, and scrapes and saves the content of each link to a file:
var wc = new WebClient();
using (var rss = XmlReader.Create(
"http://finance.google.com/finance?morenews=10&q=NASDAQ:INTC&output=rss")) {
var feed = SyndicationFeed.Load(rss);
foreach (var x in feed.Items) {
var uri = x.Links.Last().Uri;
wc.DownloadFile(uri, @"c:\rss\" + Regex.Replace(uri.LocalPath, @"^.*/", ""));
}
}
That was easy, eh? Just remember to add System.ServiceModel.Web.dll as a reference to your project. Happy syndicating.