代码之家  ›  专栏  ›  技术社区  ›  Adam Kane

如何获取RSS源项目计数?

  •  3
  • Adam Kane  · 技术社区  · 14 年前

    在C,.NET 3.5中,在Windows窗体应用程序中…

    如何获得给定RSS URL返回的项目数的整数计数?

    例子: 我的博客在: http://forgefx.blogspot.com/feeds/posts/default

    预期结果为:后计数=25

    谢谢!

    1 回复  |  直到 14 年前
        1
  •  2
  •   Marc Gravell    14 年前
    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。