Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900