XElement.Descendants () make it case-insensitive

天大地大妈咪最大 提交于 2019-12-10 18:07:43

问题


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();


来源:https://stackoverflow.com/questions/14977166/xelement-descendants-make-it-case-insensitive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!