using System; using System.Collections.Generic; using System.Linq; using System.Text; using DTG.Html; namespace ParseHtmlText { 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); // Show the tree of the html ViewHtmlDOM(html.Nodes); Console.ReadLine(); } 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 + ">"); } } } } }