XElement.Descendants () makes case insensitive

The XElement.Descendants () method accepts the name of the element found.

But it is case sensitive, is there any way to make it case insensitive

+4
source share
2 answers

You can use this:

element.Descendants() .Where(x => string.Compare(x.Name, filter, StringComparison.OrdinalIgnoreCase) == 0); 
+4
source

This method worked for me ..

 XElement selectedElement = doc.Descendants().Where(x => String.Equals((string)x.Attribute("name"), filtertext, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); 
0
source

All Articles