假设我有一个XmlNode,并且我想获取一个名为“ Name”的属性的值。我怎样才能做到这一点?
XmlTextReader reader = new XmlTextReader(path);
XmlDocument doc = new XmlDocument();
XmlNode node = doc.ReadNode(reader);
foreach (XmlNode chldNode in node.ChildNodes)
{
**//Read the attribute Name**
if (chldNode.Name == Employee)
{
if (chldNode.HasChildNodes)
{
foreach (XmlNode item in node.ChildNodes)
{
}
}
}
}
XML文件:
<Root>
<Employee Name ="TestName">
<Childs/>
</Root>