-->

XElement.Descendants () make it case-insensitive

2019-06-23 19:19发布

问题:

XElement.Descendants () method accepts name of element to be find.

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

回答1:

You can use this:

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


回答2:

This way worked for me..

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