xml删除不了!
[code=C#]
tongyong.xml
<TongYong>
<Ty>
<name> 三 </name>
<title> san </title>
<value> 100000 </value>
</Ty>
<Ty>
<name> 四 </name>
<title> dddd </title>
<value> 100000ddd </value>
</Ty>
</TongYong>
.cs
protected void rptXML_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "delete ")
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath( "~/App_Data/tongyong.xml "));
XmlNode root = doc.SelectSingleNode( "/TongYong ");
XmlNode toDelete = doc.SelectSingleNode( "/TongYong/Ty/title[ 'dddd '] ");
root.RemoveChild(toDelete.ParentNode);
doc.Save(Server.MapPath( "~/App_Data/tongyong.xml "));
}
}
[/code]
[解决办法]
XmlNode toDelete = doc.SelectSingleNode("/TongYong/Ty/title['dddd']");
root.RemoveChild(toDelete.ParentNode);
=>
XmlNode toDelete = doc.SelectSingleNode("/TongYong/Ty[title='dddd']");
toDelete.ParentNode.RemoveChild(toDelete);