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

Pittfall picture Pittfall · Jan 11, 2012 · Viewed 9.9k times · Source

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.

Answer

Jeff Mercado picture Jeff Mercado · Jan 12, 2012

Even easier:

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