I have a XML which has a node which kind of gets repeated across multiple levels in the file using C#.
Example of the XML:
As you indicated that you are working with an XmlDocument, you need to remove a child XmlElement
node via the RemoveChild method on the parent node:
string xml = @"
The Walking Dead
Test Name
1239859895
The Walking Dead
29893893893
test1
test
";
// Initialize and load the XmlDocument
var doc = new XmlDocument();
doc.LoadXml(xml);
// Delete all XmlElements named "isbn".
var list = doc.DocumentElement.GetElementsByTagName("isbn").OfType().ToArray();
foreach (var element in list)
{
var parent = element.ParentNode;
if (parent != null)
parent.RemoveChild(element);
}
var newXml = doc.OuterXml;
Debug.WriteLine(newXml);
And the output is:
The Walking Dead
Test Name
The Walking Dead
test1
test