小编Sho*_*ikh的帖子

Linq-to-XML获取带命名空间的元素

我正在使用linq-to-xml来搜索元素.

 var doc = XDocument.Load(reader);
                    var ns = doc.Root.Attribute("xmlns").Value;
                    var result = (from u in doc.Descendants(XName.Get("MyElement", ns))
Run Code Online (Sandbox Code Playgroud)

每当我尝试在xml中找到一个元素时,我都需要摆脱使用XName.Get.如何为XDocument设置默认命名空间,以便在搜索时不会打扰.

问候.

.net linq-to-xml

4
推荐指数
1
解决办法
3879
查看次数

标签 统计

.net ×1

linq-to-xml ×1