Remove XElement from XDocument Error

a9lam

New Member
I have an \[code\]XDocument\[/code\] and i want to remove \[code\]XElement\[/code\] from this.I try this code :-\[code\]XDocument XDoc = XDocument.Parse(XMLFile); var PricedItineraryRemove = XDoc.Descendants("PricedItinerary"); foreach (XElement xle in PricedItineraryRemove) { if (xle.Attribute("SequenceNumber").Value != SequenceNumber.ToString()) { xEle.Remove(); //this line giving error second time. } }\[/code\]\[code\]xEle.Remove()\[/code\] working correctly first time but second time giving \[code\]System.InvalidOperationException\[/code\] Exception.
 
Back
Top