public static XhtmlElement Parse(string html)
        {
            if (html == null)
                throw new ArgumentNullException("html");

            var htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(html);

            var doc = new XhtmlElement();

            foreach (var childNode in htmlDoc.DocumentNode.ChildNodes.OfType<HtmlNode>())
            {
                var child = childNode.ToNode(doc);
                if (child != null)
                    doc.AddChild(child);
            }

            return doc;
        }
Example #2
0
 /// <summary>
 /// Creates an HTML node from a string representing literal HTML.
 /// </summary>
 /// <param name="html">The HTML text.</param>
 /// <returns>The newly created node instance.</returns>
 public static HtmlNode CreateNode(string html)
 {
     // REVIEW: this is *not* optimum...
     HtmlDocument doc = new HtmlDocument();
     doc.LoadHtml(html);
     return doc.DocumentNode.FirstChild;
 }