I have an xml file. It contains records as in the example below.
<Simulator>
<Flight ID="1" Description="1sunny" Date="2022-09-09">
<Instructor Num="6">
<Name>matt</Name>
<Surname>matt</Surname>
<Rank>matt</Rank>
</Instructor>
</Flight>
</Simulator>
When I delete it with the delete function, I see such a result and this result breaks my auto generate id function. How can I get the flight tag to be deleted completely?
<Simulator>
<Flight />
</Simulator>
Delete function
private void b_delete_Click(object sender, EventArgs e)
{
var xDoc = XDocument.Load(input);
foreach (var elem in xDoc.Document.Descendants("Flight"))
{
foreach (var attr in elem.Attributes("ID"))
{
if (attr.Value.Equals("1"))
elem.RemoveAll();
}
}
xDoc.Save(input);
MessageBox.Show("Deleted Successfully");
}