【发布时间】:2015-07-08 13:20:08
【问题描述】:
所以基本上,处理一个 xml 文件,看起来像这样:
...
<city id="thatstheid">
<country id="anotherid"> VALUE </country>
</city>
...
我阅读了我需要使用的东西:
XmlDocument doc;//let's say this is the file im reading
XmlNode cityNode = doc.DocumentElement.SelectSingleNode("city");
cityname = cityNode.Attributes["id"].Value;
XmlNode countryNode = cityNode.SelectSingleNode("country");
countryname = countryNode.Value;
这里的问题是
countryname = countryNode.Value;
返回一个空值,即使里面有东西。
如果我尝试像这样从内部获取任何属性:
countryname = countryNode.Attributes["id"].Value;
它工作正常,所以我不知道是什么问题。
【问题讨论】:
-
@JeffreyWieder 非常感谢,很感兴趣它为什么会这样工作。