bool retval = false;
XmlDocument doc = new XmlDocument();
try
{
doc.Load(frmMain.FetchFileName(sFromFile));
XmlNodeList nodes = doc.GetElementsByTagName("Type");
foreach (XmlNode node in nodes)
{
if (node.FirstChild.InnerText == "Birthday")
{
node.ParentNode.RemoveChild(node);
doc.Save(sFromFile);
retval = true;
break;
}
}
}
catch
{
MessageBox.Show("Exception!!!", "Oops!");
return false;
}
return retval;
}
What I have tried:
I have tried the code above, as you might see the first three attempts I made, failed.
Two attempts executed the code without complaining (commented This gives no error), but
did not actually delete anything from the file. Here is a snippet of the xml file.
The code looks for and finds the birthday node, which is what I am trying to delete
so that the file should look like this afterwards:
="1.0"
<importanttype>
<type>
<name>Appointment
<predefined>Yes
.
. a bunch of other nodes in here
.
<type>
<name>Holiday
<predefined>Yes
I am baffled. Can anybody help me please?
Thanking you in anticipation, Noel.