Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq to RSS feed?

What I'm trying to do is take an RSS feel URL and, using LINQ, be able to write a query that will let me sort the subject line of the feed or sort the author line of the feed or even do 'WHERE' clauses that will let me filter by keywords for example.

I know I can read the RSS feed, parse each element, put them into some sort of class object collection and LINQ off that, but I was wondering if Microsoft provided a simpler way to do this in the .NET framework.

like image 310
Icemanind Avatar asked Jul 28 '10 21:07

Icemanind


1 Answers

You should have a look a the SyndicationFeed class.

var reader = XmlReader.Create("http://url.to/rss");
var feed = SyndicationFeed.Load(reader);

//Find items by Jesper
feed.Items.Where(i=>i.Authors.Any(p=>p.Name == "Jesper"));

//Order by publish date
var ordered = feed.Items.OrderBy(i=>i.PublishDate);
like image 158
Jesper Palm Avatar answered Oct 12 '22 00:10

Jesper Palm