0
鉴于下面的XML:的XElement空时属性存在
<root xmlns="http://tempuri.org/myxsd.xsd">
<node name="mynode" value="myvalue" />
</root>
并给予下述的代码:
string file = "myfile.xml"; //Contains the xml from above
XDocument document = XDocument.Load(file);
XElement root = document.Element("root");
if (root == null)
{
throw new FormatException("Couldn't find root element 'parameters'.");
}
如果根元素包含xmlns属性那么变量根为空。如果我删除了xmlns属性,那么root不是null。
任何人都可以解释为什么这是?