【发布时间】:2013-01-23 06:10:34
【问题描述】:
给定以下 xml:
<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 属性,则变量 root 为空。如果我删除 xmlns 属性,则 root 不为空。
谁能解释这是为什么?
【问题讨论】:
标签: xelement