c# - 如何通过属性值选择多个 XML 标记作为 XElement?

标签 c# xml linq xelement

如何选择多个 XML 标签作为 XElement,基于相同的属性进行过滤。 我有下面的代码,我想选择具有 action=true

的标签
<root>
  <first action="true">
    <path>E:\Myfolder</path>
  </first>
  <second>
    <path>C:\Users\</path>
  </second>
  <third action="true">
    <name>Mytasks</name>
  </third>
</root>

输出是这样的

  <first action="true">
    <path>E:\Myfolder</path>
  </first>
  <third action="true">
    <name>Mytasks</name>
  </third>

请大家帮帮我。我使用了 FirstorDefault() 但我只得到一条记录

最佳答案

试试这个。

$(path).find('root').find('[action="true"]')

关于c# - 如何通过属性值选择多个 XML 标记作为 XElement?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44698291/

相关文章:

c# - 为什么 ReSharper 认为 "thread.Name == null"总是错误的?

java - 使用特殊字符解析 XML

c# - 动态创建 UI 和数据库,最好的方法是什么?

c# - 将 Xml 转换为数据表

c# - 使用 LINQ 将数组对象 [,] 转换为数组

c# - 如何执行嵌套? SQL 中的请求?

c# - 使用 DateTime.TryParse() 检查几种日期格式

c# - 哪个 xml 结构允许更快的添加/删除/更新

c# - 使用 JSON.NET 返回 ActionResult

java - 在我需要做一些复杂的事情之前,JAXB 一直很好用。有哪些选择?