|
NAMEWebService::Validator::HTML::W3C - Access the W3Cs online HTML validatorSYNOPSISuse WebService::Validator::HTML::W3C; my $v = WebService::Validator::HTML::W3C->new( detailed => 1 ); if ( $v->validate("http://www.example.com/") ) { if ( $v->is_valid ) { printf ("%s is valid\n", $v->uri); } else { printf ("%s is not valid\n", $v->uri); 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); } DESCRIPTIONWebService::Validator::HTML::W3C provides access to the W3C's online Markup validator. As well as reporting on whether a page is valid it also provides access to a detailed list of the errors and where in the validated document they occur.METHODSnewmy $v = WebService::Validator::HTML::W3C->new(); Returns a new instance of the WebService::Validator::HTML::W3C object. There are various options that can be set when creating the Validator object like so: my $v = WebService::Validator::HTML::W3C->new( http_timeout => 20 );
validate$v->validate( 'http:://www.example.com/' ); Validate a URI. Returns 0 if the validation fails (e.g if the validator cannot be reached), otherwise 1. validate_file$v->validate_file( './file.html' ); Validate a file by uploading it to the W3C Validator. NB This has only been tested on a Linux box so may not work on non unix machines. validate_markup$v->validate_markup( $markup ); Validate a scalar containing HTML. Alternate interfaceYou can also pass a hash in to specify what you wish to validate. This is provided to ensure compatibility with the CSS validator module.$v->validate( uri => 'http://example.com/' ); $v->validate( string => $markup ); $v->validate( file => './file.html' ); is_valid$v->is_valid; Returns true (1) if the URI validated otherwise 0. uri$v->uri(); Returns the URI of the last page on which validation succeeded. num_errors$num_errors = $v->num_errors(); Returns the number of errors that the validator encountered. errorcountSynonym for num_errors. There to match CSS Validator interface.warningcount$num_errors = $v->warningcount(); Returns the number of warnings that the validator encountered. errors$errors = $v->errors(); foreach my $err ( @$errors ) { printf("line: %s, col: %s\n\terror: %s\n", $err->line, $err->col, $err->msg); } Returns an array ref of WebService::Validator::HTML::W3C::Error objects. These have line, col and msg methods that return a line number, a column in that line and the error that occurred at that point. Note that you need XML::XPath for this to work and you must have initialised WebService::Validator::HTML::W3C with the detailed option. If you have not set the detailed option a warning will be issued, the detailed option will be set and a second request made to the validator in order to fetch the required information. If there was a problem processing the detailed information then this method will return 0. warnings$warnings = $v->warnings(); Works exactly the same as errors only returns an array ref of WebService::Validator::HTML::W3C::Warning objects. In all other respects it's the same. validator_error$error = $v->validator_error(); Returns a string indicating why validation may not have occurred. This is not the reason that a webpage was invalid. It is the reason that no meaningful information about the attempted validation could be obtained. This is most likely to be an HTTP error Possible values are:
validator_uri$uri = $v->validator_uri(); $v->validator_uri('http://validator.w3.org/check'); Returns or sets the URI of the validator to use. Please note that you need to use the full path to the validator cgi. http_timeout$timeout = $v->http_timeout(); $v->http_timeout(10); Returns or sets the timeout for the HTTP request. OTHER MODULESPlease note that there is also an official W3C module that is part of the W3C::LogValidator distribution. However that module is not very useful outside the constraints of that package. WebService::Validator::HTML::W3C is meant as a more general way to access the W3C Validator.HTML::Validator uses nsgmls to validate against the W3Cs DTDs. You have to fetch the relevant DTDs and so on. There is also the HTML::Parser based HTML::Lint which mostly checks for known tags rather than XML/HTML validity. WebService::Validator::CSS::W3C provides the same functionality as this module for the W3C's CSS validator. IMPORTANTThis module is not in any way associated with the W3C so please do not report any problems with this module to them. Also please remember that the online Validator is a shared resource so do not abuse it. This means sleeping between requests. If you want to do a lot of testing against it then please consider downloading and installing the Validator software which is available from the W3C. Debian testing users will also find that it is available via apt-get.BUGSWhile the interface to the Validator is fairly stable it may be updated. I will endeavour to track any changes with this module so please check on CPAN for new versions if you find things break. Also note that this module is only guaranteed to work with the currently stable version of the validator. It will most likely work with any Beta versions but don't rely on it.If in doubt please try and run the test suite before reporting bugs. Note that in order to run tests against the validator service you will need to have a connection to the internet and also set an environment variable called TEST_AUTHOR. That said I'm very happy to hear about bugs. All the more so if they come with patches ;). Please use <http://rt.cpan.org/> for filing bug reports, and indeed feature requests. The code can also be found on github <https://github.com/struan/webservice-validator-html-w3c>. THANKSTo the various people on the code review ladder mailing list who provided useful suggestions.Carl Vincent provided a patch to allow for proxy support. Chris Dolan provided a patch to allow for custom user agents. Matt Ryder provided a patch for support of the explanations in the SOAP output. SUPPORTauthor email or via <http://rt.cpan.org/>.AUTHORStruan Donald <struan@cpan.org><http://www.exo.org.uk/code/> COPYRIGHTCopyright (C) 2003-2008 Struan Donald. All rights reserved.LICENSEThis program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.SEE ALSOperl(1).
Visit the GSP FreeBSD Man Page Interface. |