简体   繁体   English

如何使用C#验证html文件?

[英]How do I validate a html file with C#?

I have a C# application that receives an html file. 我有一个接收HTML文件的C#应用​​程序。 I want to parse and validate it. 我想解析并验证它。 On output it will return a list of errors or that my html is valid. 在输出时,它将返回错误列表或我的html有效。

Has anyone any idea how can I do this? 有谁知道我该怎么做?

我将运行W3C标记验证服务的本地实例,并通过API与之通信

You can use HTML Tidy. 您可以使用HTML Tidy。 There is a wrapper for .NET called TidyManaged .NET有一个名为TidyManaged的包装器

This is relevant to your question: 这与您的问题有关:

Looking for C# HTML parser 寻找C#HTML解析器

There is an obscure DLL in the framework version 1.0 (!) Microsoft.mshtml.dll and that is the only way in the framework to deal with DOM. 框架版本1.0(!) Microsoft.mshtml.dll中没有晦涩的DLL,这是框架中处理DOM的唯一方法。 If HTML is XHTML and a valid XML, then you can use XML but otherwise this is the only chance. 如果HTML是XHTML并且是有效的XML,则可以使用XML,否则这是唯一的机会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM