XML删除问题
xml文档如下:<?xml version="1.0" encoding="UTF-8"?>
<students>
<student>
<name>zhangfayu</name>
<pwd>21</pwd>
<id>123</id>
</student>
<student>
<name>lichao</name>
<pwd>23</pwd>
<id>234</id>
</student>
</students>
删除代码(根据给定的id查找相应的项并删除)
XmlDocument Doc =new XmlDocument();
XmlNodeList xnl;
Doc.Load(Application.StartupPath + "[url=file://\\students.xml]\\students.xml[/url]");
xnl = Doc.SelectSingleNode("students").ChildNodes;
for (int i = 0; i < xnl.Count; i++)
{
if (xnl.Item(i).ChildNodes.Item(1).InnerText == cmbID.SelectedItem.ToString())
{
xnl.Item(i).RemoveChild(xnl.Item(i));
}
}
红色部分为删除代码
但是执行之后xml将变为
<?xml version="1.0" encoding="UTF-8"?>
<students>
<student>
</student>
<student>
<name>lichao</name>
<pwd>23</pwd>
<id>234</id>
</student>
</students>
只删除了信息 节点却还在
问怎么才能够删除啊?
谢谢