using Winista.Text.HtmlParser;
using Winista.Text.HtmlParser.Lex;
using Winista.Text.HtmlParser.Util;
using Winista.Text.HtmlParser.Tags;
using Winista.Text.HtmlParser.Filters;
string HtmlText(string sourceHtml)
{
Parser parser = Parser.CreateParser(sourceHtml.Replace(System.Environment.NewLine,""), "utf-8");StringBuilder builderHead = new StringBuilder();
StringBuilder builderBody = new StringBuilder();NodeFilter html = new TagNameFilter("HTML");
INode nodes = parser.Parse(html)[0];
builderHead.Append(nodes.Children[0].ToHtml());
INode body = nodes.Children[1];
INode div = body.Children[0];
for (int i = 0; i < div.Children.Count; i++)
{
if (div.Children[i] is ITag)
builderBody.Append(div.Children[i].ToHtml());
}StringBuilder builder = new StringBuilder();
builder.Append("<html>");
builder.Append(builderHead.ToString());
builder.Append("<body>");
builder.Append(string.Format("<{0}>",div.GetText()));
builder.Append(builderBody.ToString());
builder.Append("</div>");
builder.Append("</body>");
builder.Append("</html>");
return builder.ToString();
}
转载于:https://www.cnblogs.com/yipeng-yu/archive/2012/02/10/2345600.html