namespaceHtmlTest { classHtmlTest { staticvoidMain(string[] args) { // Create HtmlDocument instance to load existing HTML file HTMLDocument htmlPage = new HTMLDocument(@"C:\Dev\Test\AsposeTest\HtmlTest\Sources\page1.html");
// Concatenate to get the raw string of the page // Important: use htmlDocument.DocumentElement.OuterHTML to get htmlPage's HtmlContents(outerHtml) string rawPage = htmlPage.Doctype.ToString() + htmlPage.DocumentElement.OuterHTML; Console.WriteLine(rawPage);
// Print Title and inner HTML of file to console Console.WriteLine(htmlPage.Title); Console.WriteLine(htmlPage.Body.InnerHTML);
// Get DOM node and set new text in it htmlPage.GetElementById("p1").TextContent = "modified paragraph1";
// Get a collection of specific nodes and traverse foreach(var para in htmlPage.Body.GetElementsByTagName("p")) { Console.WriteLine(para.OuterHTML); }
// Save to output the processed html htmlPage.Save("out.html"); } } }