があり、これからXDocument削除したいですXElement。
私はこのコードを試します:-
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.
}
}
xEle.Remove()1回目は正しく動作しますが、2回目はSystem.InvalidOperationException例外が発生します。