I am trying to read in data from an XML file, which I can do with the code below.
How would I then sort the data by name alphabetically to be used on an electronic menu app?
Could someone show me how to do this?
The code block below does work, but I have no idea how to sort the data alphabetically by node type.
For instance, I would like to sort by "name" alphabetically.
Other sorting methods could include sorting by price or category, etc.
Here is the XML data structure:
<?xml version="1.0" encoding="UTF-8" ?>
<base>
    <menu>
        <item>
            <category></category>  
            <name></name>
            <price></price>
            <featured></featured>
            <code></code>
            <timestart></timestart>
            <timeend></timeend>
        </item>
    </menu>
</base>
Here is the code:
public void XML_Get_MenuData()
{
    try
    {
        XmlDocument myDoc2 = new XmlDocument();
        myDoc2.Load("\\user\\today1.xml");
        XmlNodeList itemNodes = myDoc2.GetElementsByTagName("item");
        ushort i = 0;
        Menu_Items = 0;
        foreach (XmlNode sINode in itemNodes)
        {
            Category[i] = sINode["category"].InnerText;
            Console.PrintLine("category: {0}", Category[i]);
            ItemName[i] = sINode["name"].InnerText;
            Console.PrintLine("name: {0}", ItemName[i]);
            Price[i] = sINode["price"].InnerText;
            Console.PrintLine("price: {0}", Price[i]);
            Featured[i] = sINode["featured"].InnerText;
            Console.PrintLine("featured: {0}", Featured[i]);
            if (Featured[i] == "yes")
            {
                uFeatured[i] = 1;
            }
            else
            {
                uFeatured[i] = 0;
            }
            Code[i] = sINode["code"].InnerText;
            Console.PrintLine("code: {0}", Code[i]);
            TimeStart[i] = sINode["timestart"].InnerText;
            Console.PrintLine("timestart: {0}", TimeStart[i]);
            TimeEnd[i] = sINode["timeend"].InnerText;
            Console.PrintLine("timeend: {0}", TimeEnd[i]);
            i++;
        }
        Menu_Items = i;
        Console.PrintLine("Menu Items: {0}", Menu_Items);
    }
    catch
    {
        Console.PrintLine("missed Menu Items: {0}");
    }
}
 
     
    