LINQ到XML递归删除元素-C#

LINQ到XML递归删除元素-C#,c#,linq,linq-to-xml,C#,Linq,Linq To Xml,我有以下XML: <Root> <Section name="xyz" /> <Section name="abc"> <Section name="def" /> </Section> <Section name="abc"> <Section name="def"> <Section name="xyz" /> <Section name="abc"

我有以下XML:

<Root>
 <Section name="xyz" />
 <Section name="abc">
   <Section name="def" />
 </Section>
 <Section name="abc">
   <Section name="def">
     <Section name="xyz" />
     <Section name="abc" />
     <Section name="xyz">
       <Section name="xyz" />
     </Section>
  </Section>
</Section>
</Root>

我有XML的
XDocument
表示。如何遍历树并使用say
abc

删除所有元素,这非常简单:)

我一定很喜欢LINQ to XML

编辑:我刚刚用您的示例XML进行了尝试,结果如下:

<Root>
  <Section name="abc">
    <Section name="def" />
  </Section>
  <Section name="abc">
    <Section name="def">
      <Section name="abc" />
    </Section>
  </Section>
</Root>


如果这不是您所期望的,请告诉我。

当Jon Skeet回答时,我甚至不需要验证:)谢谢Jon!顺便说一下,我假设我也可以在连接条件中使用
子体
?类似于
var j=from h in doc.substands(“Section”)的东西在..
@Nick:绝对可以。它只返回一个
IEnumerable
<Root>
  <Section name="abc">
    <Section name="def" />
  </Section>
  <Section name="abc">
    <Section name="def">
      <Section name="abc" />
    </Section>
  </Section>
</Root>