e-mid wrote:
Here is an xml structure. i want to remove <a> nodes that do not have any
child. How can i do that in csharp?
<root>
<a>
<b/>
</a>
<a/>
<a/>
<a>
<c/>
</a>
</root>
The following works for me with .NET 1.1:
using System;
using System.Xml;
public class Test20040630 {
public static void Main (string[] args) {
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"test20040630.xml");
XmlNodeList aElements = xmlDocument.SelectNodes(@"//a[not(node())]");
Console.WriteLine(aElements.Count);
foreach (XmlNode node in aElements) {
node.ParentNode.RemoveChild(node);
}
Console.WriteLine(xmlDocument.OuterXml);
}
}
However I am not sure it is reliable to use foreach while you are
removing nodes in the collection from the document.
--
Martin Honnen
http://JavaScript.FAQTs.com/