C# one-liner to grab specific data from an RSS feed [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question 开发者_开发知识库I'm looking for a C# "one-liner" (need not strictly be a single line, but very short is preferable) way to download an RSS feed from a given HTTP URL, and extract specific data. Robustness be damned. Something that doesn't require any external libraries.
Specifically I want to count the number of <item>
s in the RSS. But some kind of LINQ method that could be reused to, say for example, return a list of the item <title>
elements would be most useful, if it can be kept short.
Regex.Matches(new WebClient().DownloadString("http://stackoverflow.com/feeds/question/7180063"), "<entry>").Count
What about something like this:
var rssFeed = XDocument.Load("http://weblogs.asp.net/scottgu/rss.aspx");
var posts = from item in rssFeed.Descendants("item")
select new
{
Title = (string)item.Element("title"),
Published = (DateTime?)item.Element("pubDate"),
Url = (string)item.Element("link"),
};
Source.
SyndicationFeed.Load(XmlReader.Create("http://weblogs.asp.net/scottgu/rss.aspx")).Items.Count();
精彩评论