private bool goDeeper(XMLElement node) { bool result = false; if (node.hasChildren()) { List <XMLElement> chList = node.getChildrenList(); XMLElement child; for (int i = 0; i < chList.Count; ++i) { child = chList[i]; if (goDeeper(child)) { if (!node.hasAttribute(child.Name)) { node.addAttribute(new XMLAttribute(child.Name, child.getText())); node.removeChildAt(i); --i; // to keep it normal } } } var newChild = new XMLElement("newChild"); newChild.addAttribute(new XMLAttribute("status", "added")); node.addChild(newChild); } else { if (!node.hasAttributes()) { result = true; } } return(result); }