How to select nodes where the node name contains "mystring"

I need to get an XmlNodeList where the 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> 

Required conclusion

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

I tried something like XmlNodeList mystringElements = xmlDocument.SelectNodes(@"//*[contains(name,'mystring')]");

But it returns zero node. What should I put in an XPath request for this.

+4
source share
1 answer

You need to use the name() function. Only name will try to match an element with the name "name".

Do you want to:

 //*[contains(name(),'mystring')] 
+11
source

Source: https://habr.com/ru/post/1307682/


All Articles