【发布时间】:2013-07-29 14:27:14
【问题描述】:
在下面的程序中,helloElem 不为空,正如预期的那样。
string xml = @"<root>
<hello></hello>
</root>";
XDocument xmlDoc = XDocument.Parse(xml);
var helloElem = xmlDoc.Root.Element("hello"); //not null
如果给 XML 一个命名空间:
string xml = @"<root xmlns=""namespace"">
<hello></hello>
</root>";
XDocument xmlDoc = XDocument.Parse(xml);
var helloElem = xmlDoc.Root.Element("hello"); //null
为什么helloElem 变为空?在这种情况下如何获取 hello 元素?
【问题讨论】:
标签: c# .net xml linq linq-to-xml