我应该如何显示元素的子节点属性中包含的值?请考虑以下示例:
<?xml version="1.0" encoding="utf-8"?>
<Segments>
<Segment ID="AAA">
<Elements>
<Element ID ="11" />
<Element ID ="22" El/>
<Element ID ="33" />
</Elements>
</Segment>
</Segments>
C# 代码
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(MyXMLFileLocation);
XmlNodeList xnList = xmlDocument.SelectNodes(/Segments/Segment[@ID='AAA']/Elements);
foreach (XmlNode xn in xnList)
{
if (xn.HasChildNodes)
{
foreach (XmlNode childNode in xn.ChildNodes)
{
// How should I fetch the attributes of childnodes here. I have to show the value contained in ID attributes
}
}
}