如何选择节点名称包含“ mystring”的节点。 [英] How to select nodes where node name contains "mystring"

查看:65
本文介绍了如何选择节点名称包含“ mystring”的节点。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取XmlNodeList,其中节点名称包含 mystring

I need to get XmlNodeList where node name contains "mystring"

XML

    <?xml version="1.0" encoding="utf-8"?>
<root>
  <node1>
    node1 value
  </node1>
  <node2_mystring>
    node2 value
  </node2_mystring>
  <node3>
    node3 value
  </node3>
  <node4_mystring>
    node 4 value
  </node4_mystring>
</root>

所需的输出为

<?xml version="1.0" encoding="utf-8"?>
<root>
  <node2_mystring>
    node2 value
  </node2_mystring>
  <node4_mystring>
    node 4 value
  </node4_mystring>
</root>

我尝试了类似 XmlNodeList mystringElements = xmlDocument.SelectNodes(@ // * [包含(name,'mystring')]);

但它返回零节点。我应该在XPath查询中添加些什么来实现此目的。

But it returns zero node. What should I put in XPath query to achieve this.

推荐答案

您需要使用 name() 函数。只是 name 会尝试匹配名为 name的元素。

You need to use the name() function. Just name alone will try to match an element named "name".

您想要这个:

//*[contains(name(),'mystring')]

这篇关于如何选择节点名称包含“ mystring”的节点。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆