I Have a XML file that I want remove a node that it's content is 'test'. I search entire Google, so doesn't help me or I can't get my answer. The XML file content is shown below:
<?xml version="1.0" encoding="utf-8"?>
<parent>
<child>C#</child>
<child>VB</child>
<child>VB.net</child>
<child>F#</child>
<child>C++</child>
<child>C</child>
<child>Ruby</child>
<child>Pascal</child>
<child>test</child>
<child>python</child>
</parent>
I can load it to any list. So my address is OK. But can't remove the node that its content is test.
One of my tried code is:
XmlDocument doc = new XmlDocument();
doc.Load(Address);
XmlNode node = doc.SelectSingleNode("/parent/child[text()='test']");
doc.ParentNode.RemoveChild(node);
doc.Save(Address);
any suggestion will be appreciable.
Update: Thanks to Andrei Vatasescu the correct answer is:
node.ParentNode.RemoveChild(node);
instead of :
doc.ParentNode.RemoveChild(node);