【发布时间】:2011-05-30 15:17:48
【问题描述】:
我有以下 xml 结构:
<systemtest>
<test id="0">
<name>Test One</name>
</test>
<test id="1">
<name>Test Two</name>
</test>
</systemtest>
名称显示在数据网格的第 1 列中,其中第 2 列有一个带有删除按钮的按钮列。
我如何准确地使用 xpath 并导航到当前节点让我们说 test id="0" 并删除它(包括名称)?
我不清楚我怎么能对这个方法说他要删除哪一行。
XmlDocument XMLDoc = new XmlDocument();
XMLDoc.Load(XMLFile);
XPathNavigator nav = XMLDoc.CreateNavigator();
nav.SelectSingleNode("...."); //??
nav.DeleteSelf(); //will this do the trick?
ID 也是在一个单独的类中生成的,上面的方法应该是。
var node = nav.SelectSingleNode("/testsystem/test[@id='0']");
node.DeleteSelf();
XMLDoc.Save(XMLFile);
这确实会删除第一个项目,但第二个项目会崩溃。 我如何根据我在数据网格中按下的按钮将其变为绑定的变量?
提前致谢。
【问题讨论】: