Geeks With Blogs

News My Blog has been MOVED to
Michael Freidgeim's OLD Blog My Blog has been MOVED to

We’ve used HtmlAgilityPack based function IsValidHtmlFragment(string html) to validate dynamically loaded Html Fragments before inserting into main page(or do not insert if it is invalid) and recently noticed that it doesn’t return false for some fragments with not closed tags.

I decided to find some other tool to call from the code and found that most of HTML parcers are too forgivven(like browsers) or too strict- to check full XHTML conformance.
I am going to add manual procedure to run Tidy.EXE (parameters are listed here)or use Tidy Online to FIX the errors before adding new html into the system, but still want to ensure, that Html with incorrect structure not inserted.

I found an article “C# Validate XHTML” with source code and decided to use it as a start point. Unfortunately there are quite a few things in the original code, that didn’t work as I expected/wanted, so I had to spend much more time to change it that I originally thought. Thanks to Sam Allen for very responsive answers.
I’ve put source code of this class to  and consider to add it to codeplex at

Other options, that I’ve looked :

TidyManaged- I noticed it after writing the class and not checked it yet. It may be solve what I want to have. -USELESS, because download link is broken. (code project has slightly older version of the same article -does parsing, but not validation. How to write a regular expression to validate text input as Html? -
regex isn't the best solution for parsing HTML.

W3C Markup Validator library in C #

If I understood it correctly, it assumes that file is a valid XML document. Also it has restrictive GNU license.


Free Broken Links Validators


W3C Link Checker
Worried about broken links in your web documents? This online validator from the W3 Consortium is able to recursively check your document for dead links. You simply enter a URL in the form provided, and it will visit your site and check the links.

Doesn’t validates frame pages from frameset, quite slow.e.g my site main page document processed in 264.04 seconds.

Xenu Link Sleuth: Find Broken Links
Xenu is a utility for Windows that checks your web site for broken links. It can work both with a "live" website as well as on a copy of your web site residing on your own hard disk. It's a favourite of many webmasters for checking broken links on their site.

I haven’t try it yet.

Posted on Wednesday, June 1, 2011 6:36 AM ASP.NET , CSS/DHTML/JavaScript | Back to top

Comments on this post: Validation of Html file

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: