XElement.Descendants () make it case-insensitive

后端 未结 2 1348
长发绾君心
长发绾君心 2020-12-21 06:03

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

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

相关标签:
2条回答
  • 2020-12-21 06:17

    You can use this:

    element.Descendants()
           .Where(x => string.Compare(x.Name, filter,
                                      StringComparison.OrdinalIgnoreCase) == 0);
    
    0 讨论(0)
  • 2020-12-21 06:21

    This way worked for me..

    XElement selectedElement = doc.Descendants().Where(x => 
    String.Equals((string)x.Attribute("name"), filtertext, 
    StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
    
    0 讨论(0)
提交回复
热议问题