谁能解释我为什么无法使用此查询删除此子节点。它给我一个错误,指出“ System.Xml.dll中发生了'System.ArgumentException'类型的未处理的异常。附加信息:要删除的节点不是该节点的子节点。”
XmlDocument xDoc = new XmlDocument();
xDoc.Load("sample.xml");
xDoc.RemoveChild(xDoc.SelectSingleNode("//Class[@Name='ECMInstruction']/Property[@Id='2']/Lists[contains(ListName,'ws_Users')]"));
xDoc.Save("sample.xml");
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Class Name="ECMInstruction" Style="Top">
<Entity Id="1" Name="DocumentInformation" />
<Property Id="1">
</Property>
<Property Id="2">
<Lists>
<ListName>ws_Users</ListName>
<ListName>dfdfdfd</ListName>
</Lists>
</Property>
</Class>
</Root>
未经测试的尝试:
XmlDocument xDoc = new XmlDocument();
xDoc.Load("sample.xml");
var parent = xDoc.SelectSingleNode("//Class[@Name='ECMInstruction']/Property[@Id='2']/Lists");
var nodeToRemove = parent.SelectSingleNode("ListName[text() = 'ws_Users')]");
parent.RemoveChild(nodeToRemove);
xDoc.Save("sample.xml");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句