Remove Empty XML Nodes
Join the DZone community and get the full member experience.
Join For FreeRemove 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);
}
XML
Opinions expressed by DZone contributors are their own.
Comments