XmlDocument doc = new XmlDocument();
doc.Load(iePath +
"\\RadioBarPresets.xml");
foreach (XmlNode node in doc.DocumentElement.ChildNodes)
{
if (node.Name == "Genre_Genre_" + genre)
{
node.RemoveAll();
}
}
doc.Save(iePath + \\RadioBarPresets.xml);
It removes all values...but leaves the entries below in the xml file:
If I remove the Genre "Dance"....(for every element removed, left behind is-)
<Genre_Genre_Dance />
<Genre_Genre_Dance />
<Genre_Genre_Dance />
<Genre_Genre_Dance />
<Genre_Genre_Dance />
<Genre_Genre_Dance />

Delete XML elements
aspfun
Still can't figure where "node" is...
Is your for loop supposed to be nested within the foreach (only place "node" is)...
MrZap
cablehead,
try this:
XmlDocument doc =
new XmlDocument ();doc.Load (Path.Combine (iepath, "RadioBarPresets.xml"));
XmlNodeList list = doc.GetElementsByTagName (string.Format ("Genre_Genre_{0}", genre));
XmlNode root = doc.SelectSingleNode ("/RadioBar");
for (int i = list.Count - 1; i >= 0; i--) {
root.RemoveChild (list [ i ]);
}
HTH
--mc
DMAR330
OMG!
for( Int32 i = doc.DocumentElement.ChildNodes.Count - 1; i >= 0; i-- )
{
XmlNode n = node.ChildNodes[ i ];
if( n.Name == "RemoveMe" ) doc.DocumentElement.ChildNodes.Remove(n);
}
Good Coding!
Javier Luna
http://guydotnetxmlwebservices.blogspot.com/
Programm3r
Great!
for( Int32 i = doc.DocumentElement.ChildNodes.Count - 1; i >= 0; i-- )
{
XmlNode n = doc.DocumentElement.ChildNodes[ i ];
if( n.Name == "RemoveMe" ) doc.DocumentElement.ChildNodes.Remove( n );
}
Please, dont ask me about 'doc' variable ;)
Good Coding!
Javier Luna
http://guydotnetxmlwebservices.blogspot.com/
jcsam
Hi cablehead,
You should use this snippet code:
for
( Int32 i = node.ChildNodes.Count - 1; i >= 0; i-- ){
XmlNode n = node.ChildNodes[ i ];
if( n.Name == "RemoveMe" ) node.ChildNodes.Remove(n);
}
Good Coding!
Javier Luna
http://guydotnetxmlwebservices.blogspot.com/
thomasabcd
Where is node coming from in your code
XmlNode XmlNodeList
if( n.Name == "RemoveMe" ) node.ChildNodes.Remove(n);
----no definition for Remove....
Bob Beauchemin