How do I validate a html file with C#?

2019-01-20 10:34发布

I have a C# application that receives an html file. I want to parse and validate it. On output it will return a list of errors or that my html is valid.

Has anyone any idea how can I do this?

4条回答
Luminary・发光体
2楼-- · 2019-01-20 10:59

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. If HTML is XHTML and a valid XML, then you can use XML but otherwise this is the only chance.

查看更多
Lonely孤独者°
3楼-- · 2019-01-20 11:14

I'd run a local instance of the W3C Markup Validation service and communicate with it via the API

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-20 11:17

You can use HTML Tidy. There is a wrapper for .NET called TidyManaged

查看更多
\"骚年 ilove
5楼-- · 2019-01-20 11:22

This is relevant to your question:

Looking for C# HTML parser

查看更多
登录 后发表回答