Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在发布日期前从新闻网站订购RSS源_C#_.net_Xml_Linq_Rss - Fatal编程技术网

C# 如何在发布日期前从新闻网站订购RSS源

C# 如何在发布日期前从新闻网站订购RSS源,c#,.net,xml,linq,rss,C#,.net,Xml,Linq,Rss,我正在使用.net 4并阅读新闻网站上的RSS源- 我使用转发器将feed放入页面,但我刚刚注意到feed并不总是对发布日期进行排序。似乎有一个奇怪的群体 如何明确指定它是按发布日期DESC排序的 这就是我目前所拥有的 private void PopulateRssFeed() { //BBC UK string RssFeedUrl = "http://feeds.bbci.co.uk/news/uk/rss.xml?edition=uk"; List<Fe

我正在使用.net 4并阅读新闻网站上的RSS源-

我使用转发器将feed放入页面,但我刚刚注意到feed并不总是对发布日期进行排序。似乎有一个奇怪的群体

如何明确指定它是按发布日期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;
    }
}
private void PopulateRssFeed()
{
//英国广播公司
字符串RssFeedUrl=”http://feeds.bbci.co.uk/news/uk/rss.xml?edition=uk";
列表提要=新列表();
尝试
{
XDocument xDoc=新的XDocument();
xDoc=XDocument.Load(RssFeedUrl);
//Take 3限制要显示的项目数
//i、 e-
//var items=(从xDoc.subjects(“item”)中的x开始)。取(3)
var items=(从xDoc.subjects(“item”)中的x开始)
选择新的
{
title=x.元素(“title”).值,
link=x.元素(“link”).值,
pubDate=x.Element(“pubDate”).值,
描述=x.元素(“描述”).值
});
如果(项!=null)
{
foreach(项目中的var i)
{
feed f=新feed
{
Title=i.Title,
Link=i.Link,
PublishDate=i.PublishDate,
描述
};
添加(f);
}
}
Repeater1.DataSource=feed;
Repeater1.DataBind();
}
捕获(例外情况除外)
{
掷骰子;
}
}
使用LINQ:

另外,
永远不能为
,因此
如果(项!=null)
不需要检查。

使用LINQ:


顺便说一句,
永远不能为
因此
如果(项!=null)
检查是不需要的。

谢谢-也谢谢你的项空提示。谢谢-也谢谢你的项空提示。
var items = (from x in xDoc.Descendants("item")
             orderby (DateTime)x.Element("pubDate") descending
             select new
             {
                 title = x.Element("title").Value,
                 link = x.Element("link").Value,
                 pubDate = x.Element("pubDate").Value,
                 description = x.Element("description").Value
             });