【问题标题】:XLinq: Remove certain XElements from a xml file which are saved in a LIst<XElement>Xlinq:从保存在 LIst<XElement> 中的 xml 文件中删除某些 XElement
【发布时间】:2010-08-27 12:47:36
【问题描述】:

我无法在迭代节点时删除它们,没关系。'

我有一个包含 Guid 的列表。

我想删除该 xml 文件中 XElement 具有该列表的 Guid 的所有 XElement

这是我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<Departments>
  <Department Id="2d55ba71-a2ab-44a1-a697-f57bbd238c7f" />
  <Department Id="775cd4c2-74c9-4f41-9ddf-1126c508cccb" />
</Departments>

这不起作用:xDoc.Descendants("Department ").Remove&lt;XElement&gt;().Where...

我怎样才能做到这一点?

【问题讨论】:

    标签: xml linq xelement


    【解决方案1】:

    我只是快速猜测,但试试这个:

    xDoc.Descendants("Department").Where(/* match code */).Remove();
    

    【讨论】:

    • xDoc.Descendants("Department").Where(e => e.Attribute("Id").Value.Equals(id)).Remove();谢谢一堆!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    相关资源
    最近更新 更多