【发布时间】:2016-03-24 09:29:38
【问题描述】:
我正在使用 .net 4 并从新闻网站阅读 RSS 提要 - http://feeds.bbci.co.uk/news/uk/rss.xml?edition=uk
我已经使用转发器将提要进入页面,但我刚刚注意到提要并没有一直对发布日期 DESC 进行排序。似乎有一个奇怪的分组。
如何明确指定它是按出版日期 DESC 排序的?
这就是我目前所拥有的......
private void PopulateRssFeed()
{
//BBC UK
string RssFeedUrl = "http://feeds.bbci.co.uk/news/uk/rss.xml?edition=uk";
List<Feeds> feeds = new List<Feeds>();
try
{
XDocument xDoc = new XDocument();
xDoc = XDocument.Load(RssFeedUrl);
//Take 3 Limits the number of items to display
//i.e -
//var items = (from x in xDoc.Descendants("item").Take(3)
var items = (from x in xDoc.Descendants("item")
select new
{
title = x.Element("title").Value,
link = x.Element("link").Value,
pubDate = x.Element("pubDate").Value,
description = x.Element("description").Value
});
if (items != null)
{
foreach (var i in items)
{
Feeds f = new Feeds
{
Title = i.title,
Link = i.link,
PublishDate = i.pubDate,
Description = i.description
};
feeds.Add(f);
}
}
Repeater1.DataSource = feeds;
Repeater1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}
【问题讨论】: