// Create an instance of an HTML document using (var document = new HTMLDocument()) { var body = document.Body; // Create a paragraph element var p = (HTMLParagraphElement)document.CreateElement("p"); // Set a custom attribute p.SetAttribute("id", "my-paragraph"); // Create a text node var text = document.CreateTextNode("my first paragraph"); // Attach the text to the paragraph p.AppendChild(text); // Attach the paragraph to the document body body.AppendChild(p); // Save the HTML document to a file document.Save(Path.Combine(OutputDir, "edit-document-tree.html")); }