我正在MSDN上检查有关检查XmlNode
属性是否存在的方法的XmlNode.Attributes topic。好吧,没有关于如何检查项目的示例。
我有类似这样的东西:
//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
可以吗?
<myTag text="something" isChecked />
。 - IvanXmlNode.Attributes
属性可能为空。nodes?.Attributes["IsCapital"] != null
- Arin Taylor