problem when remove element of XMl doc

Joined
Nov 6, 2007
Messages
1
Reaction score
0
I have a XML file : DefaultControlInfo.xml
<ControlInfo>
<Control Name="Control1">
<name>Yello</name>
</Control>
<Control Name="Control2">
<name>Red</name>
</Control>
<Control Name="Control3">
<name>Green</name>
</Control>
</ControlInfo>

then my code to remove:

XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("~/DefaultControlInfo.xml"));
foreach (XmlNode xnode in xdoc.DocumentElement.ChildNodes)
{
if (xnode.Attributes["Name"].Value != null)
{
xdoc.DocumentElement.RemoveChild(xnode);
}
}
xdoc.Save(Server.MapPath("~/DefaultControlInfo.xml"));

Result : new DefaultControlInfo.xml file
<ControlInfo>
<Control Name="Control1">
<name>Yello</name>
</Control>
<Control Name="Control3">
<name>Green</name>
</Control>
</ControlInfo>

My question is : why it didn't remove Control3 ??????? :neutral:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top