Submit Your Article
Join the WebProWorld Forum!
– Close + Open
Facebook Twitter Google Buzz

Easily Follow WebProNews

Follow us on Facebook, Twitter, Buzz... it's up to you.


Text: Decrease Font Size Increase Font Size | Print Print Article | Share: Delicious Digg StumbleUpon Post to Twitter Post to Facebook



Using the API for the W3C HTML Validator

Monday, November 27, 2006

The W3C has introduced an API for their HTML Validator.

It is not a SOAP web service, but it does return XML that can be parsed, so now you have the ability to incorporate validation to any web application, Windows program or wherever you want. It works just as the normal validator, by specifying a URL, but you have to add the "output=soap12" parameter to the URL like so: http://validator.w3.org/check?uri=http://www.google.com&output=soap12.

I've been playing a little with the possibilities and created a class that encapsulates the validation process and wraps the results up in a suitable class.

The collection of errors and warnings can be bound directly to a GridView or Repeater without additional code.

This gives you a very easy, but powerful way of dealing with the validator.

Examples of use

Even thought the class is very small and its functionality limited, it still gives you all the relevant information from the validation.

Here's an example of some of the possibilities of the class.

using (HtmlValidator val = new HtmlValidator("http://www.google.com"))

{

   if (!val.Validate())

   {

     grid.DataSource = val.Errors; // or val.Warnings

     grid.DataBind();

     lbDoctype.Text = val.Doctype;

     lbCharset.Text = val.Charset.BodyName;

     foreach (HtmlValidator.ValidationError error in val.Errors)

     {

     DoSomething(error.Message, error.LineNumber, error.ColumnIndex);

     }

   }
}

Implementation

Download HtmlValidator.cs below and add it to any C# project. If you want to use it in an ASP.NET project, just put it in the App_Code folder.

Download

HtmlValidator.zip (1,43 KB)

Tag:

Add to Del.icio.us | Digg | Reddit | Furl

Bookmark WebProNews:

Mads Kristensen currently works as a Senior Developer at Traceworks located
in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in
2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and
web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

About the author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

Yep, the download link is

Yep, the download link is still broker. :(

Publish A Comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
17 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
SEARCH