我有一個XML文件中的數據如下:如何在XML數據上使用LINQ執行OrderBy?
<history>
<history-item id="1">
<history-url>www.google.com/ncr</history-url>
<history-date>29/06/2017</history-date>
<history-time>5:27:25PM</history-time>
</history-item>
<history-item id="2">
<history-url>www.yahoo.com</history-url>
<history-date>10/03/2017</history-date>
<history-time>5:30:25PM</history-time>
</history-item>
<history-item id="4">
<history-url>www.google.com/ncr</history-url>
<history-date>23/01/2014</history-date>
<history-time>5:27:25PM</history-time>
</history-item>
<history>
我的目標是小組和秩序這一數據基於history-date
。 我使用下面的代碼,以實現這一目標:
XDocument history = XDocument.Load("history.xml");
var details =
from c in history.Descendants("history-item")
group c by c.Element("history-date").Value into d
select new
{
Value = d.Key,
Rows = d.Elements("history-url")
};
details = details.OrderBy(c => c.Value);
然而,問題在於 - 日期僅由即一天,dd
排序。
當我嘗試打印,輸出結果是:
10/03/2017
23/01/2014
29/06/2017
所需的輸出是:
23/01/2014
10/03/2017
29/06/2017
任何幫助表示讚賞!