单击按钮清除所有子节点 [英] clear all child nodes on button click
问题描述
大家好,
我在代码中有问题..我想当我单击按钮时,我的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屋!