Empty all XML nodes of a certain type using C#

I currently have a XML document built using the following structure:

<a>
     ....
     <b>
           <c>
           </c>
           <d>
           ....
           </d>
     </b>
</a>
<a>
   ....

I would like to parse this XML document using C# and output a document in which all the b-nodes are emptied, without losing my b-node. Thus creating the following result:

<a>
   ...
   <b />
</a>
<a>
   ...

Can anyone show me the way to do this?

Jon Skeet
people
quotationmark

LINQ to XML would make this pretty simple:

var doc = XDocument.Load(...);
var bs = doc.Descendants("b").ToList();
foreach (var b in bs)
{
    b.ReplaceNodes();
}

(Use ReplaceAll instead of ReplaceNodes if you want to remove the attributes within b nodes as well.)

people

See more on this question at Stackoverflow