我想从 XML 文件中检索信息,但是它的格式化方式很奇怪。这里是...
<?xml version="1.0"?>
<Careers>
<CareerList>
<CareerName></CareerName>
<CareerDescription></CareerDescription>
</CareerList>
<CareerList>
<CareerName>Cook</CareerName>
<CareerDescription>Cooks food for people</CareerDescription>
</CareerList>
</Careers>
我想获得第二个值,即 Cook 和 Cooks food for people 的描述,但我只得到空节点。例如...
public string CareerDescription(string CareerFile)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(CareerFile);
string Description = xmlDoc.SelectSingleNode("Careers/CareerList/CareerDescription").InnerText;
return Description;
}
我将如何选择第二个节点而不是第一个节点?