I create a class for managing XML, I created an overload of my RemoveNode method
public partial class HWXml { public string XmlFile; private XmlDocument XmlDoc = new XmlDocument(); public HWXml(string XmlFile) { this.XmlFile = XmlFile; } public XmlNode SelectSingleNode(string NodePath) { XmlDoc.Load(XmlFile); return XmlDoc.SelectSingleNode(NodePath); } public void RemoveNode(XmlNode removeChild) { XmlDoc.Load(XmlFile); removeChild.ParentNode.RemoveChild(removeChild); XmlDoc.Save(XmlFile); } public void RemoveNode(string RemoveChild) { XmlDoc.Load(XmlFile); XmlNode removeChild = XmlDoc.SelectSingleNode(RemoveChild); removeChild.ParentNode.RemoveChild(removeChild); XmlDoc.Save(XmlFile); } }
When I try to remove a node using a string parameter, it works
private void RemoveXML_Click(object sender, RoutedEventArgs e) { MyXmlClass myXmlClass = new MyXmlClass(XmlFile); myXmlClass.RemoveNode("root/Content"); }
But when I try to delete the node using the XmlNode parameters, it will compile, execute, not display an error message, but will not delete any effect in the XML file.
private void RemoveXML_Click(object sender, RoutedEventArgs e) { MyXmlClass myXmlClass = new MyXmlClass(XmlFile); XmlNode node = myXmlClass.SelectSingleNode("root/Conteudo"); myXmlClass.RemoveNode(node); }
What is the problem?
source share