【问题标题】:XElement.Descendants () make it case-insensitiveXElement.Descendants () 使其不区分大小写
【发布时间】:2013-02-20 10:09:50
【问题描述】:

XElement.Descendants () 方法接受要查找的元素的名称。

但它是区分大小写的,有什么办法让它不区分大小写

【问题讨论】:

    标签: xml linq xpath xelement descendant


    【解决方案1】:

    你可以用这个:

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

    【讨论】:

    • 如果这种方法有任何问题的可能性
    • @user1750877:你在想什么样的问题?
    【解决方案2】:

    这种方式对我有用..

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

    【讨论】:

      猜你喜欢
      • 2016-10-30
      • 2020-04-08
      • 2012-12-01
      • 2013-03-06
      • 2020-02-18
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      • 1970-01-01
      相关资源
      最近更新 更多