static void Main(string[] args)
var doc = new XmlDocument();
doc.LoadXml("<a><c>text</c><b/><ggg/><fff/></a>");
RemoveEmptyChildNodes(doc);
Console.WriteLine(doc.OuterXml);
private static void RemoveEmptyChildNodes(XmlDocument node)
foreach (var childNode in node.ChildNodes.OfType<XmlNode>())
RemoveEmptyChildNodes(childNode, node);
private static void RemoveEmptyChildNodes(XmlNode node, XmlNode parent)
foreach (var childNode in node.ChildNodes.OfType<XmlNode>().Where(x => x.NodeType != XmlNodeType.Text && x.NodeType != XmlNodeType.Attribute).ToList())
RemoveEmptyChildNodes(childNode, node);
if (node.InnerXml == String.Empty)
parent.RemoveChild(node);