I have a res/xml/myxmlfile which looks something like this (sorry for the screenshot, I am unsure how to display the xml file properly in the stackoverflow editor):
<Food>
<Pizza>
<type>Salami</type>
<type>Pepperoni</type>
<type>Hawaiian</type>
</Pizza>
<Burger>
<type>Chicken</type>
<type>Bacon</type>
<type>Cheese</type>
</Burger>
<Soup>
<type>Pumpkin</type>
<type>Sweet Corn</type>
<type>Vegetarian</type>
</Soup>
</Food>
I want to write a function that takes the type of food as a parameter (e.g. Burger) and loads all the items between the tags into a string[i].
So function would be something like this:
public string[] GetAllSubFoodTypes (string foodtype)
{
string[] contents;
//--- pseudocode as I don't know how to do this
Loadxmlfile
Find the <foodtype> tag in file
Load all data between <type> and </type> into the string[] contents
return contents;
}
Example of how you'd call the function from main:
string[] subFoodType;
subFoodType = GetAllSubFoodTypes("Burger")
Contents of subFoodType will then be:
subFoodType[0]
will be "Chicken", subFoodType[1]
will be "Bacon" and so on.