在C#、.NET 3.5中的Windows Forms应用程序中,如何获取给定RSS URL返回的项目数量的整数计数?
例如: 对于我的博客:http://forgefx.blogspot.com/feeds/posts/default 预期结果应为:postCount = 25
谢谢!
例如: 对于我的博客:http://forgefx.blogspot.com/feeds/posts/default 预期结果应为:postCount = 25
谢谢!
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();
}
}
}
(需要引用System.ServiceModel.Web.dll
)
使用SyndicationFeed
的优点在于同时支持RSS和Atom。