单击按钮清除所有子节点 [英] clear all child nodes on button click

查看:66
本文介绍了单击按钮清除所有子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在代码中有问题..我想当我单击按钮时,我的xml文件的所有子节点都已清除.仅剩下我的父节点.

xml结构:-

< images>
< imgName>
text1
</imgName>

< imgName>
text2
</imgName>
</images>


我想当我单击按钮时,我的xml文件子节点已被删除,只有我的父节点还剩.按钮单击后的xml结构如下所示..

< images>

</images>

请快速帮助
thnx

hi guys,

i have a problem in code.. i want when i click on a button my xml file''s all child node has been clear. only my parent node is remaining.

xml structure:-

<images>
<imgName>
text1
</imgName>

<imgName>
text2
</imgName>
</images>


i want when i click on button my xml files child node has been deleted only my parent noe is remaning. after button click xml structure is look like this..

<images>

</images>

please help quick
thnx

推荐答案

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("image.xml"));
 
XmlNode node = xmlDoc.SelectSingleNode("/images/imgName");
XmlNode commonParent = node.ParentNode;
 
if(node != null)
{
    commonParent.RemoveAll();
}
 
xmlDoc.Save(Server.MapPath("image.xml"));


[


source[^]


这篇关于单击按钮清除所有子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆