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 c开发者_高级运维lass object collection and LINQ off that, but I was wondering if Microsoft provided a simpler way to do this in the .NET framework.
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);
Maybe this is what you are searching for:
http://codebetter.com/blogs/jeffrey.palermo/archive/2007/10/13/linq-to-xml-querying-an-rss-feed.aspx
精彩评论