开发者

How to get RSS feed item count?

In C#, .NET 3.5, in a Windows Forms application...

How开发者_高级运维 does one get the integer count of the number of items that a given RSS url returns?

Example: For my blog at: http://forgefx.blogspot.com/feeds/posts/default

The expected result would be: postCount = 25

Thanks!


using System.ServiceModel.Syndication;
using System.Linq;
class Program
{
    static void Main()
    {
        using(XmlReader source = XmlReader.Create(
                 "http://forgefx.blogspot.com/feeds/posts/default")) {
            int count = SyndicationFeed.Load(source).Items.Count();
        }
    }
}

(requires a reference to System.ServiceModel.Web.dll)

An advantage of using SyndicationFeed is that you support RSS and Atom at the same time.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜