static void ProcessElement(DomNode e) { if (e.NodeType == DomNodeType.Text && !Utility.IsData((DomText)e)) { var domText = (DomText)e; e.ReplaceWith(ExtractNodes(domText.OwnerDocument, domText.Data)); return; } if (e.ChildNodes.Count == 0) { return; } // TODO Array allocation to allow modification to children is wasteful (performance) foreach (var c in e.ChildNodes.ToArray()) { ProcessElement(c); } }