XElement.Descendants () make it case-insensitive

2019-06-23 19:21发布

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条回答
等我变得足够好
2楼-- · 2019-06-23 19:33

You can use this:

element.Descendants()
       .Where(x => string.Compare(x.Name, filter,
                                  StringComparison.OrdinalIgnoreCase) == 0);
查看更多
啃猪蹄的小仙女
3楼-- · 2019-06-23 19:47

This way worked for me..

XElement selectedElement = doc.Descendants().Where(x => 
String.Equals((string)x.Attribute("name"), filtertext, 
StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
查看更多
登录 后发表回答