时间:2010-07-25 01:46:01

标签: asp.net html tidy

1 个答案:

答案 0 :(得分:1)

TidyManaged是一个用于开源,跨平台Tidy库的管理.NET / Mono包装器,一个HTML / XHTML / XML标记解析器&最初由Dave Raggett创建的清洁工。

样本用法

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);
    }
  }
}

结果:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 13), see www.w3.org" />
<title>test</title>
</head>
<body>
asd
</body>
</html>

请注意,<title>test</tootle>已更改为正确的<title>test</title>

https://github.com/markbeaton/TidyManaged