The XPathExpression class allows you to add sort specifications.
Here is some sample code that should work with .NET 2.0:
XPathDocument doc = new XPathDocument(@"..\..\XMLFile1.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathExpression exp = nav.Compile("Messages/Message");
exp.AddSort(
"number(concat(substring(date, 7), substring(date, 4, 2), substring(date, 1, 2)))",
XmlSortOrder.Descending,
XmlCaseOrder.None,
null,
XmlDataType.Number
);
foreach (XPathNavigator msg in nav.Select(exp))
{
Console.WriteLine(
"{0}: {1}",
msg.SelectSingleNode("date").Value,
msg.SelectSingleNode("messagetext").Value
);
}
With XMLFile1.xml being
<Messages>
<Message>
<messagetext>Message 2</messagetext>
<date>04.02.2010</date>
</Message>
<Message>
<messagetext>Message 1</messagetext>
<date>05.02.2010</date>
</Message>
<Message>
<messagetext>Message 3</messagetext>
<date>05.02.2009</date>
</Message>
</Messages>
the output is
05.02.2010: Message 1
04.02.2010: Message 2
05.02.2009: Message 3
Assumed date format is ddmmyyyy but you could change those substring expressions as needed if you want mmddyyyy.