Over a million developers have joined DZone.

Remove Empty XML Nodes

·
Remove nodes like  (without attributes & without children)

public static void RemoveEmptyNodes(XmlDocument doc)
{
  XmlNodeList nodes = doc.SelectNodes("//node()");
            
  foreach (XmlNode node in nodes)
    if ((node.Attributes.Count == 0) && (node.ChildNodes.Count == 0))
      node.ParentNode.RemoveChild(node);
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}