Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of LTjake (4001)

Friday August 06, 2004
09:51 AM

Validator->RSS

[ #20271 ]

Ben Hammersley has a neat bit of code to take the W3C's validator results and spit back an RSS feed.

It's pretty neat, but it only reports validation errors -- nothing for success, nor connection errors.

By letting WebService::Validator::HTML::W3C do the hard work, I was able to add those few details to Ben's cool idea.

#!/usr/bin/perl

use strict;
use warnings;

use WebService::Validator::HTML::W3C;
use CGI;
use XML::RSS;

my $validator = WebService::Validator::HTML::W3C->new( detailed => 1 );
my $query     = CGI->new;
my $rss       = XML::RSS->new;
my $url       = $query->param( 'url' );
my $link      = "http://validator.w3.org/check?uri=$url";

$rss->channel( title => "Validation results for $url" );
$rss->channel( link  => $link );

if ( $validator->validate( $url ) ) {
    if ( $validator->is_valid ) {
        $rss->add_item(
            title       => 'This Page Is Valid!',
            link        => $link,
            description => "$url is valid."
        );
    }
    else {
        foreach my $error ( @{ $validator->errors } ) {
            $rss->add_item(
                title       => 'Line ' . $error->line . ', ' . $error->msg,
                link        => $link,
                description => 'Line ' . $error->line . ', ' . $error->msg
            );
        }
    }
}
else {
    $rss->add_item(
        title       => 'Validation Error',
        link        => $link,
        description => $validator->validator_error
    );
}

print $query->header( 'application/rss+xml' ), $rss->as_string;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.