<Security>
- <User>
<Username>jon</Username>
<Password>khan</Password>
<UserFolder>aliHomeDIR</UserFolder>
</User>
- <User>
<Username>bob</Username>
<Password>khan</Password>
<UserFolder>aliHomeDIR</UserFolder>
</User>
</Security>
I have xml file and i want to remove specific element having username jon
foreach (XmlNode parentNode in parentNodes)
{
for (int i = 0; i <= parentNode.ChildNodes.Count - 1; i++)
{
XmlNode childNode = parentNode.ChildNodes[i];
if (childNode.Name == "Username" && childNode.InnerXml == textBox1.Text.Trim())
{
childNode.ParentNode.RemoveAll();
xmlDoc.Save(filename);
//MessageBox.Show(childNode.InnerXml.ToString());
}
}
}
but using this code it removes inner part of <User> tag
<User>
</User>
instead of complete
<User>
<Username>jon</Username>
<Password>khan</Password>
<UserFolder>aliHomeDIR</UserFolder>
</User>