public static void Main()
<h1>This is <b>bold</b> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
var htmlDoc = new HtmlDocument();
var htmlBody = htmlDoc.DocumentNode.SelectSingleNode("//body");
HtmlNode h1Node = HtmlNode.CreateNode("<h1> This is new heading</h1>");
HtmlNode pNode = HtmlNode.CreateNode("<p> This is new paragraph 1</p>");
HtmlNodeCollection newChildren = new HtmlNodeCollection(htmlBody);
htmlBody.PrependChildren(newChildren);
Console.WriteLine("\n****After prepending children****\n");
static void DisplayNode(HtmlNode node)
Console.WriteLine("Node Name: " + node.Name);
Console.Write("\n" + node.Name + " children:\n");
static void DisplayChildNodes(HtmlNode nodeElement)
HtmlNodeCollection childNodes = nodeElement.ChildNodes;
if (childNodes.Count == 0)
Console.WriteLine(nodeElement.Name + " has no children");
foreach (var node in childNodes)
if (node.NodeType == HtmlNodeType.Element)
Console.WriteLine(node.OuterHtml);