【发布时间】:2010-07-06 09:06:03
【问题描述】:
当我尝试使用 RemoveChild() 删除我的一些子元素时。但是抛出异常。 我在下面附上了我的代码。
nodeName = doc.SelectSingleNode("//Equipment//DataCollections//EnabledIDs//MyID[@id='" + attrValue + "']");
// Found the nodeName successfully druing run time.
doc.DocumentElement.RemoveChild(nodeName);
// faild to Remove the node
在下面显示错误:
An unhandled exception of type 'System.ArgumentException' occurred in System.Xml.dll
Additional information: The node to be removed is not a child of this node.
如何删除节点?
[更新]
使用 VS2005 和 .NET 2.0。
【问题讨论】:
-
似乎子节点在被选中时与其创建它的父实例“无关”。这对我来说似乎是一个错误。解决方法是(正如其他人所说):
childNode.ParentNode.RemoveChild(childNode)
标签: c# xml c#-2.0 removechild selectsinglenode