private StringBuilder Display(Element node, StringBuilder currentTree) { // Open tag currentTree.Append(new string(' ', this.displayDepthLevel * DisplayDepthSpaces)) .Append("<") .Append(node.Type) .Append(">") .AppendLine(); this.displayDepthLevel++; foreach (var child in node.SubElements) { currentTree = this.Display(child, currentTree); } // Closing tag this.displayDepthLevel--; currentTree.Append(new string(' ', this.displayDepthLevel * DisplayDepthSpaces)) .Append("<") .Append(node.Type) .Append("/>") .AppendLine(); return currentTree; }
public void Remove(Element element) { if (element == null) { throw new InvalidOperationException("Child cannot be null!"); } SubElements.Remove(element); }
public void Add(Element child) { if (child == null) { throw new InvalidOperationException("Child cannot be null!"); } this.Children.Add(child); }
public bool Remove(Element child) { if (child == null) { throw new InvalidOperationException("Child cannot be null!"); } var removed = this.Children.Remove(child); return removed; }
public static void Main() { Element html = new Element( "html", new Element("head"), new Element("body", new Element("section", new Element("h2"), new Element("p"), new Element("span")), new Element("footer"))); File.WriteAllText("index.txt", html.Display(0)); }