Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SelectNodes with XPath ignoring cases in node names

I have a problem similar to the question SelectNodes with XPath ignoring cases but in my case the uppercase/lowercase problem is in the node with the name 'application' (Sometimes is 'Application' other times 'application').

How would i apply the solution of the other post? or a different one applies in this case?

xml:

<?xml version="1.0" encoding="utf-16" ?>
<application>
  <forms>
    <action type="update">
      <form uid="" >
      </form>
    </action>
  </forms>
</application>

In C# 3.5:

XmlNode nodex= oXMLDoc1.SelectSingleNode("Application/forms/action/form/@uid")
nodex.Value="UniqueIDx";//nodex is null :S
like image 435
VSP Avatar asked Dec 09 '22 23:12

VSP


1 Answers

We may convert xml and our variables to lower case.

string value = "aBc";
XmlNode xmlnode = xmldoc.SelectSingleNode(string.Format("/some/path/add[translate(@key, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = '{0}']", value.ToLower()));
like image 168
mykhailovskyi Avatar answered Dec 11 '22 11:12

mykhailovskyi