|
This is the case, I can delete everything in the node <User> </ User> with the following program, but I cannot delete the <User> </ User> node
protected void DeleteButton_Click (object sender, EventArgs e)
{
XmlDocument Doc = new XmlDocument ();
Doc.Load (Server.MapPath (".\\db\\dbGuest.xml"));
XmlNodeList NodeList = Doc.SelectSingleNode ("dbGuest"). ChildNodes;
foreach (XmlNode xn in NodeList)
{
XmlElement xe = (XmlElement) xn;
XmlNodeList node = xe.GetElementsByTagName ("Name");
if (node.Count> 0)
{
if (node [0] .InnerText == ddlName.SelectedItem.Text)
{
xe.RemoveAll ();
break;
}
}
//xn.RemoveAll ();
}
Doc.Save (Server.MapPath (".\\db\\dbGuest.xml"));
DataBind ();
}
XML file:
<? xml version = "1.0" standalone = "yes"?>
<dbGuest>
<User>
<Name> asfew3ere1sfasf </ Name>
</ User>
<User>
<Name> asfew3243232cvd1sfasf </ Name>
</ User>
</ dbGuest>
For example, I pressed the DeleteButton to delete the second <User> </ User>. The XML file I want is like this:
<? xml version = "1.0" standalone = "yes"?>
<dbGuest>
<User>
<Name> asfew3ere1sfasf </ Name>
</ User>
</ dbGuest>
But what I actually get is this:
<dbGuest>
<User>
<Name> asfew3ere1sfasf </ Name>
</ User>
<User>
</ User>
</ dbGuest>
How to solve it? |
|