using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTG.Html; namespace CreateHtmlDoc { class Program { static string indent = ""; static void Main(string[] args) { string htmltext = "
Bold text
before
Italic text
"; // Build DOM of the html HtmlDoc html = HtmlDoc.ParseHTML(htmltext); // The function changes text style from italic to underline ScanHtmlTree(html.Nodes); // Show the tree of the html ViewHtmlDOM(html.Nodes); Console.ReadLine(); } static void ScanHtmlTree(HtmlNodeCollection nodes) { foreach (HtmlNode node in nodes) { if (node.IsElement) { HtmlTag tag = node as HtmlTag; if (tag.Attributes.IndexOf("style") != -1) tag.Attributes["style"].Value = "text-decoration:underline;"; ScanHtmlTree(tag.Nodes); } } } static void ViewHtmlDOM(HtmlNodeCollection nodes) { foreach (HtmlNode node in nodes) { if (node.IsText) { HtmlText text = node as HtmlText; Console.WriteLine(indent + text.ToString()); } else { HtmlTag tag = node as HtmlTag; Console.WriteLine(indent + tag.ToString()); indent += " "; ViewHtmlDOM(tag.Nodes); indent = indent.Substring(0, indent.Length - 2); Console.WriteLine(indent + "" + tag.Name + ">"); } } } } }