Example #1
0
        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;
        }
Example #2
0
 public void Remove(Element element)
 {
     if (element == null)
     {
         throw new InvalidOperationException("Child cannot be null!");
     }
     SubElements.Remove(element);
 }
Example #3
0
        public void Add(Element child)
        {
            if (child == null)
            {
                throw new InvalidOperationException("Child cannot be null!");
            }

            this.Children.Add(child);
        }
Example #4
0
        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));
        }