【发布时间】:2011-11-16 13:02:01
【问题描述】:
我在 MSDN 上检查 XmlNode.Attributes topic 关于检查 XmlNode 是否存在给定名称的属性的方法。好吧,没有关于如何检查项目的示例。
我有类似的东西:
//some code here...
foreach (XmlNode node in n.SelectNodes("Cities/City"))
{
//is there some method to check an attribute like
bool isCapital = node.Attributes.Exist("IsCapital");
//some code here...
}
那么,检查每个节点中是否存在属性的最佳方法是什么?
用node.Attribute["IsCapital"]!=null可以吗?
【问题讨论】: