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 newChild = HtmlNode.CreateNode("<h1> This is added at the beginning</h>");
htmlBody.PrependChild(newChild);
Console.WriteLine("\n****After prepending child node****\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);