我想读取 XML 文件的一些值。我可以读取一些值,但我想获取<tools></tools>
-tags 之间的信息。
XmlNodeList xnList = xml.SelectNodes("/instructions/Steps");
foreach (XmlNode xn in xnList)
{
XmlNodeList xnChildList = xn.ChildNodes;
foreach (XmlNode xnc in xnChildList)
{
MessageBox.Show("ID: " + xnc["ID"].InnerText + "Desc: " + xnc["desc"].InnerText);
//this one is working so far!
//I tried to create a new XMLNodeList
XmlNodeList testNodeList = xnc.SelectNodes("/tools");
foreach (XmlNode node in testNodeList)
{
MessageBox.Show(node["tool"].InnerXml);
}
}
}
但它不起作用。我该如何解决工具部分?
XML 文件如下所示:
<instructions>
<Steps QualificationID="12,3">
<Step>
<ID>1.1</ID>
<desc>desc</desc>
<tools>
<tool ID = "1" name = "10Zoll Steckschl" />
<tool ID = "2" name = "5Zoll Steckschl" />
</tools>
</Step>
<Step>
<ID>1.2</ID>
<desc>desc2</desc>
<tools>
<tool ID = "3" name = "11Zoll Steckschl" />
<tool ID = "4" name = "54Zoll Steckschl" />
</tools>
</Step>
</Steps>
<Steps QualificationID="1223,3">
<Step>
<ID>2.1</ID>
<desc>desc3</desc>
<tools>
<tool ID = "5" name = "14Zoll Steckschl" />
<tool ID = "6" name = "2Zoll Steckschl" />
</tools>
</Step>
<Step>
<ID>2.2</ID>
<desc>desc4</desc>
<tools>
<tool ID = "7" name = "13Zoll Steckschl" />
<tool ID = "8" name = "4Zoll Steckschl" />
</tools>
</Step>
</Steps>
</instructions>