我正在尝试读取我想为妈妈制作的xml文件.基本上这就是我想做的事情:
ComboBox将显示XML中的所有蔬菜名称.ComboBox将显示XML中的食谱名称,该名称可以使用在第一个菜单中选择的蔬菜ComboBox进行烹饪.Button,所选配方将读取通向配方的文件路径.<Vegetables>
<vegetable name="Carrot">
<recipe name="ABCrecipe">
<FilePath>C:\\</FilePath>
</recipe>
<recipe name="DEFrecipe">
<FilePath>D:\\</FilePath>
</recipe>
</vegetable>
<vegetable name="Potato">
<recipe name="CBArecipe">
<FilePath>E:\\</FilePath>
</recipe>
<recipe name"FEDrecipe">
<FilePath>F:\\</FilePath>
</recipe>
</vegetable>
</Vegetables>
Run Code Online (Sandbox Code Playgroud)
private void Form1_Load(object sender, EventArgs e)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load("Recipe_List.xml");
XmlNodeList vegetables = xDoc.GetElementsByTagName("Vegetable");
for (int i = 0; i < vegetables.Count; i++)
{
comboBox1.Items.Add(vegetables[i].Attributes["name"].InnerText);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//I'm lost at …Run Code Online (Sandbox Code Playgroud)