tags:

views:

35

answers:

1

Hi,

I have a XMLDocument like:

<Folder name="test">
         <Folder name="test2">
              <File>TestFile</File>
         </Folder>
 </Folder>

I want only the folder´s, not the files. So, how to delete / manipulate the XML Document in c# to delete / remove ALL elements in the document?

Thanks!

+2  A: 

If you can use XDocument and LINQ, you can do

XDocument doc = XDocument.Load(filename) // or XDocument.Parse(string)
doc.Root.Descendants().Where(e => e.Name == "File").Remove();

-- edited out an error

Jens