Hi, I have an xmlnodelist in C# I would like sort by ID without creating arrays. The XML data is loaded into a dynamic table I've created. I haven't studied a lot XPATH but I figured out by Googling the attached code could work. Howevern, I would like to get the sorted output back as an xmlnodelist in order to create the dynamic table easily. Is this possible?
(http://forums.asp.net/t/1226980.aspx):
public partial class DefaultSamePage : System.Web.UI.Page
{
//a public var XmlNodeList, in order to use it both in sortNodeList and another function
XmlNodeList sortedNodes;
}
void sortNodeList()
{
XPathDocument myQuiz = new XPathDocument(Server.MapPath("quiz.xml"));
XPathNavigator nav = myQuiz.CreateNavigator();
XPathExpression myExp = nav.Compile("//question");
myExp.AddSort("@id", XmlSortOrder.Descending, XmlCaseOrder.None, "", XmlDataType.Number);
XPathNodeIterator iter = nav.Select(myExp);
while (iter.MoveNext())
{
// is this possible?
sortedNodes = iter.Current.Value;
}
}