views:

60

answers:

1

Hello,

I can not remove nodes while I iterate them thats ok.´

I have a List with Guid`s in it.

I want to delete all XElements in that xml file where the XElement has a Guid of that List

thats my xml file:

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

That does not work: xDoc.Descendants("Department ").Remove<XElement>().Where...

How can I make that work?

A: 

I'm just guessing quickly but try this:

xDoc.Descendants("Department").Where(/* match code */).Remove();
Codesleuth
xDoc.Descendants("Department").Where(e => e.Attribute("Id").Value.Equals(id)).Remove();thx a bunch!
msfanboy