How to create an html document from scratch using the HtmlAgility pack

.net dom html-agility-pack

Question

I just wanted to create my own simple document using the agility pack so create a new HtmlDocument that contains just the basic container elements - i.e.

<html><head></head><body></body></html>

How can I do this from scratch without actually loading the htmldocument with anything.

Accepted Answer

Even easier:

var doc = new HtmlDocument();
var node = HtmlNode.CreateNode("<html><head></head><body></body></html>");
doc.DocumentNode.AppendChild(node);



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why