开发者

How to get RSS feed item count?

开发者 https://www.devze.com 2023-01-03 14:22 出处:网络
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?

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

精彩评论

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