sealed class MyDumper { private class Helper { public Node Node; public Helper Parent; public string ParentIndent; public bool Last; } public static string Dump(Node root) { var sb = new StringBuilder(); var workStack = new Stack(); var droot = new Helper {Parent = null, Node = root, ParentIndent = ""}; workStack.Push(droot); while (workStack.Count > 0) { var current = workStack.Pop(); if (current.Parent != null) { sb.Append(current.Parent.ParentIndent); current.ParentIndent = current.Parent.ParentIndent + (current.Last?" ":"│")+ " "; // my indent sb.Append(current.Last ? "└" : "├"); sb.Append("-"); } else current.ParentIndent = ""; sb.AppendLine(current.Node.Text); for (int index = current.Node.Children.Count-1; index>=0; index--) { var node = current.Node.Children[index]; var dnode = new Helper {Node = node, Parent = current, Last = index==current.Node.Children.Count-1}; workStack.Push(dnode); } } return sb.ToString(); } }