Use a local copy of the W3C validator


On Ubuntu install the following packages using sudo aptitude install w3c-dtd-xhtml w3c-linkchecker w3c-markup-validator

dpkg -L w3c-markup-validator shows that the sample apache configuration file is at /etc/w3c/w3c-markup-validator-apache-perl.conf and the executable is at /usr/lib/cgi-bin/check

Change /etc/hosts w3c.local to resolve to 127.0.0.1

Copy the Apache configuration file and wrap it with a virtual host configuration.

Then access the page via http://w3c.local/w3c-markup-validator/


examples/www/w3c.conf
<VirtualHost *:80>
    ServerName   w3c.local

    ScriptAlias /w3c-markup-validator/check /usr/lib/cgi-bin/check
    ScriptAlias /w3c-markup-validator/checklink /usr/lib/cgi-bin/checklink
    Alias /w3c-markup-validator /usr/share/w3c-markup-validator/html

<Location /w3c-markup-validator>
  Options +Includes +MultiViews
  AddHandler server-parsed .html
</Location>
</VirtualHost>


examples/www/w3c_validate.pl
#!/usr/bin/perl
use strict;
use warnings;

use Data::Dumper;
use WebService::Validator::HTML::W3C;

my $v = WebService::Validator::HTML::W3C->new(
    detailed    =>  1,
    validator_uri => 'http://w3c.local/w3c-markup-validator/check',
);

if ( $v->validate_file('index.html') ) {
    if ( $v->is_valid ) {
        print "OK\n";
        printf ("%s is valid\n", $v->uri);
    } else {
        print "Failed\n";
        printf ("%s is not valid\n", Dumper $v->uri);
        printf("Num errors %s\n", $v->num_errors);
        #print $v->errors;
        print $v->_content;
        #foreach my $error ( @{$v->errors} ) {
        #    printf("%s at line %d\n", $error->msg, $error->line);
        #}
    }
} else {
    printf ("Failed to validate the website: %s\n", $v->validator_error);
}