I have an XML document for which I want to sort specific nodes alphabetically.
XML document
2724
2474
2246
1309
Desired output
Dentist (1309)
Doctor (2246)
Pharmacy (2724)
Physiotherapy (2474)
Current ASP.NET code
dim node as XmlNode = objXML.SelectSingleNode("response/lst[@name=""facet_counts""]/lst[@name=""facet_fields""]/lst[@name=""professions_raw_nl""]")
Dim sbuilder As New StringBuilder
Dim navigator As XPathNavigator = node.CreateNavigator()
Dim selectExpression As XPathExpression = navigator.Compile("???")
selectExpression.AddSort("????", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text)
Dim nodeIterator As XPathNodeIterator = navigator.Select(selectExpression)
While nodeIterator.MoveNext()
'how can I print the name and value of the node?
End While
解决方案
Since all answers seem to work with Linq and I just wanted to use regular VB.NET I now added each node in an Arraylist and used the regular Array.Sort() on it.
Does the trick.