2017-12-13 10 views
0

私はMVCでRSSを使ってwired.comからフィードを取得しています。しかし、私はすべての飼料を必要としない、私はちょうど最初の5つのフィードが必要ですこれどうやってするの?RSS get First Five商品

 WebClient wclient = new WebClient(); 
     string RSSData = wclient.DownloadString("https://www.wired.com/feed/rss"); 
     return View(); 

     Document xml = XDocument.Parse(RSSData); 
     var RSSFeedData = (from x in xml.Descendants("item") 
          select new RSSFeed 
          { 
           Title = ((string)x.Element("title")), 
           Link = ((string)x.Element("link")) 
          }); 

答えて

0

Enumerable.Take(int)を使用できます。 がここに要素

IEnumerable<RSSFeed> RSSFeedData = (from x in xml.Descendants("item") 
          select new RSSFeed 
          { 
           Title = ((string)x.Element("title")), 
           Link = ((string)x.Element("link")) 
          }).Take(5); 

の指定された数を返しますドキュメント https://msdn.microsoft.com/it-it/library/bb503062(v=vs.110).aspx

関連する問題