小编Ebr*_*adi的帖子

XElement.Descendants不适用于命名空间

我有一个简单的XML,

<S xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><H></H></S>
Run Code Online (Sandbox Code Playgroud)

我想找到所有"H"节点.

XElement x = XElement.Parse("<S xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><H></H></S>");
IEnumerable<XElement> h = x.Descendants("H");
if (h != null)
{
}
Run Code Online (Sandbox Code Playgroud)

但是这段代码不起作用.当我从S标记中删除命名空间时,代码正常工作.

xelement namespaces

16
推荐指数
2
解决办法
6668
查看次数

标签 统计

namespaces ×1

xelement ×1