使用RemoveChild()删除子节点
我想仅删除此一个节点,例如:
此 XML 中的
,例如:
<Tests> <Test ID="0" AllowMultipleSelect="1">
<Name>BaseSamples</Name>
<Sample ID="546" Type="0">Sample1 </Sample>
<Sample ID="135" Type="0">Sample45</Sample>
<Sample ID="544" Type="0">Sample2</Sample>
<Sample ID="5818" Type="0" >Sample78</Sample>
</Test>
</Tests>
这样我的结果如下:
<Tests> <Test ID="0" AllowMultipleSelect="1">
<Name>BaseSamples</Name>
<Sample ID="546" Type="0">Sample1 </Sample>
<Sample ID="135" Type="0">Sample45</Sample>
<Sample ID="5818" Type="0" >Sample78</Sample>
</Test>
</Tests>
我可以一次删除任何一个节点(因为我放置了一个循环来检查需要删除的示例 ID) 任何帮助将不胜感激,提前致谢。
I would like to delete just this one node, for example:
<Sample ID="544" Type="0">Sample2</Sample>
from this XML, for example:
<Tests> <Test ID="0" AllowMultipleSelect="1">
<Name>BaseSamples</Name>
<Sample ID="546" Type="0">Sample1 </Sample>
<Sample ID="135" Type="0">Sample45</Sample>
<Sample ID="544" Type="0">Sample2</Sample>
<Sample ID="5818" Type="0" >Sample78</Sample>
</Test>
</Tests>
so that my results something like this:
<Tests> <Test ID="0" AllowMultipleSelect="1">
<Name>BaseSamples</Name>
<Sample ID="546" Type="0">Sample1 </Sample>
<Sample ID="135" Type="0">Sample45</Sample>
<Sample ID="5818" Type="0" >Sample78</Sample>
</Test>
</Tests>
I would be okay with deleting any one node at a time (since I put a loop to check for sample IDs that need to be deleted)
Any help would be appreciated, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过简单的搜索就在网上找到了这个:
Found this online with a simple search:
我还没有测试过这段代码,但它应该可以工作。
I haven't tested this code but it should work.