谁对XML熟,教教我怎么删除XML这个节点
<?xml version="1.0" encoding="gb2312"?>
<Root>
<Item ID="2">
<Name>ddddd</Name>
<Introduction>ddddddddddd</Introduction>
</Item>
<Item ID="4">
<Name>ddd</Name>
<Introduction>dssssssssss</Introduction>
</Item>
<Item ID="555">
<Name>dfgdfg</Name>
<Introduction>dfgdfgd</Introduction>
</Item>
<Item ID="555">
<Name>555</Name>
<Introduction>aaaaaaaaaaaaa</Introduction>
</Item>
<Item ID="2333">
<Name>dsfs</Name>
<Introduction>dfsdfd</Introduction>
</Item>
</Root>
我现在能取到id="2333"这个2333的值
<Item ID="2333">
<Name>dsfs</Name>
<Introduction>dfsdfd</Introduction>
</Item>
能不能通过这个 2333的值把这段节点删除掉
[AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
public string DeleteAll(string id)(这个id就是2333的值)
{
try
{
XmlDocument xmlDoc = new XmlDocument();
//加载xml文件
xmlDoc.Load("TestWeb/SectionsXml.xml");
//查找根节点
XmlNode studentsNode = xmlDoc.SelectSingleNode("Root");
foreach (XmlNode userNode in studentsNode)
{
XmlElement xe = (XmlElement)userNode;
//如果当前<User>节点ID等于ListView当前选中项的索引
string aa = xe.GetAttribute("ID");
if (xe.GetAttribute("ID") == id)
{
//移除指定节点
//<Students>移除指定的<User>
studentsNode.RemoveChild(userNode);
//每次都要保存
xmlDoc.Save("TestWebSectionsXml.xml");
break;
}
else
{
return "0";
}
}
return "1";
}
catch
{
return "0";
}
}