开发者

C# one-liner to grab specific data from an RSS feed [closed]

Closed. This question is off-topic. It is not currently accepting answers.

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜