0

我在.net 中为 HtmlTidy 使用这个库包装器

https://github.com/markbeaton/TidyManaged

它有一个简单的例子:

using System;
using TidyManaged;

public class Test
{
 public static void Main(string[] args)
 {
   using (Document doc = Document.FromString("<hTml><title>test</tootle>     <body>asd</body>"))
   {
  doc.ShowWarnings = false;
  doc.Quiet = true;
  doc.OutputXhtml = true;
  doc.CleanAndRepair();
  string parsed = doc.Save();
  Console.WriteLine(parsed);
  }
 }
}

我想将库用于一段 HTML 而不是带有“html”和“body”标签的完整页面,这可能吗?

我基本上想验证一个开始和结束标签等,并删除没有匹配的标签,任何其他伟大的工具都会很好。

4

2 回答 2

1

我通过使用找到了答案:

 doc.OutputBodyOnly = AutoBool.Yes;

但结果我得到的是乱码字符而不是 UTF-8(我使用希伯来字符)并发现它是一个 3 岁的开放错误.... https://github.com/markbeaton/TidyManaged/issues/2 这并没有解决问题: doc.InputCharacterEncoding = TidyManaged.EncodingType.Utf8; doc.OutputCharacterEncoding = TidyManaged.EncodingType.Utf8;

@Oscar 我会检查你的推荐谢谢

于 2014-03-27T12:25:02.797 回答
0

过去我使用 Tidy .Net 取得了不错的成绩

http://sourceforge.net/projects/tidynet/

于 2014-03-27T10:34:01.630 回答