1WebService::Validator::UHsTeMrL:C:oWn3tCr(i3b)uted PerlWDeobcSuemrevnitcaet:i:oVnalidator::HTML::W3C(3)
2
3
4

NAME

6       WebService::Validator::HTML::W3C - Access the W3Cs online HTML
7       validator
8

SYNOPSIS

10           use WebService::Validator::HTML::W3C;
11
12           my $v = WebService::Validator::HTML::W3C->new(
13                       detailed    =>  1
14                   );
15
16           if ( $v->validate("http://www.example.com/") ) {
17               if ( $v->is_valid ) {
18                   printf ("%s is valid\n", $v->uri);
19               } else {
20                   printf ("%s is not valid\n", $v->uri);
21                   foreach my $error ( @{$v->errors} ) {
22                       printf("%s at line %d\n", $error->msg,
23                                                 $error->line);
24                   }
25               }
26           } else {
27               printf ("Failed to validate the website: %s\n", $v->validator_error);
28           }
29

DESCRIPTION

31       WebService::Validator::HTML::W3C provides access to the W3C's online
32       Markup validator. As well as reporting on whether a page is valid it
33       also provides access to a detailed list of the errors and where in the
34       validated document they occur.
35

METHODS

37   new
38           my $v = WebService::Validator::HTML::W3C->new();
39
40       Returns a new instance of the WebService::Validator::HTML::W3C object.
41
42       There are various options that can be set when creating the Validator
43       object like so:
44
45           my $v = WebService::Validator::HTML::W3C->new( http_timeout => 20 );
46
47       validator_uri
48           The URI of the validator to use.  By default this accesses the W3Cs
49           validator at http://validator.w3.org/check. If you have a local
50           installation of the validator ( recommended if you wish to do a lot
51           of testing ) or wish to use a validator at another location then
52           you can use this option. Please note that you need to use the full
53           path to the validator cgi.
54
55       ua  The user agent to use. Should be an LWP::UserAgent object or
56           something that provides the same interface. If this argument is
57           provided, the "http_timeout" and "proxy" arguments are ignored.
58
59       http_timeout
60           How long (in seconds) to wait for the HTTP connection to timeout
61           when contacting the validator. By default this is 30 seconds.
62
63       detailed
64           This fetches the XML response from the validator in order to
65           provide information for the errors method. You should set this to
66           true if you intend to use the errors method.
67
68       proxy
69           An HTTP proxy to use when communicating with the validation
70           service.
71
72       output
73           Controls which output format is used. Can be either xml or soap12.
74
75           The default is soap12 as the XML format is deprecated and is likely
76           to be removed in the future.
77
78           The default will always work so unless you're using a locally
79           installed Validator you can safely ignore this.
80
81   validate
82           $v->validate( 'http:://www.example.com/' );
83
84       Validate a URI. Returns 0 if the validation fails (e.g if the validator
85       cannot be reached), otherwise 1.
86
87   validate_file
88           $v->validate_file( './file.html' );
89
90       Validate a file by uploading it to the W3C Validator. NB This has only
91       been tested on a Linux box so may not work on non unix machines.
92
93   validate_markup
94           $v->validate_markup( $markup );
95
96       Validate a scalar containing HTML.
97
98   Alternate interface
99       You can also pass a hash in to specify what you wish to validate. This
100       is provided to ensure compatability with the CSS validator module.
101
102               $v->validate( uri => 'http://example.com/' );
103               $v->validate( string => $markup );
104               $v->validate( file => './file.html' );
105
106   is_valid
107           $v->is_valid;
108
109       Returns true (1) if the URI validated otherwise 0.
110
111   uri
112           $v->uri();
113
114       Returns the URI of the last page on which validation succeeded.
115
116   num_errors
117           $num_errors = $v->num_errors();
118
119       Returns the number of errors that the validator encountered.
120
121   errorcount
122       Synonym for num_errors. There to match CSS Validator interface.
123
124   errors
125           $errors = $v->errors();
126
127           foreach my $err ( @$errors ) {
128               printf("line: %s, col: %s\n\terror: %s\n",
129                       $err->line, $err->col, $err->msg);
130           }
131
132       Returns an array ref of WebService::Validator::HTML::W3C::Error
133       objects.  These have line, col and msg methods that return a line
134       number, a column in that line and the error that occurred at that
135       point.
136
137       Note that you need XML::XPath for this to work and you must have
138       initialised WebService::Validator::HTML::W3C with the detailed option.
139       If you have not set the detailed option a warning will be issued, the
140       detailed option will be set and a second request made to the validator
141       in order to fetch the required information.
142
143       If there was a problem processing the detailed information then this
144       method will return 0.
145
146   warnings
147       ONLY available with the SOAP output from the development Validator at
148       the moment.
149
150           $warnings = $v->warnings();
151
152       Works exactly the same as errors only returns an array ref of
153       WebService::Validator::HTML::W3C::Warning objects. In all other
154       respects it's the same.
155
156   validator_error
157           $error = $v->validator_error();
158
159       Returns a string indicating why validation may not have occurred. This
160       is not the reason that a webpage was invalid. It is the reason that no
161       meaningful information about the attempted validation could be
162       obtained. This is most likely to be an HTTP error
163
164       Possible values are:
165
166       You need to supply a URI to validate
167           You didn't pass a URI to the validate method
168
169       You need to supply a URI with a scheme
170           The URI you passed to validate didn't have a scheme on the front.
171           The W3C validator can't handle URIs like www.example.com but
172           instead needs URIs of the form http://www.example.com/.
173
174       Not a W3C Validator or Bad URI
175           The URI did not return the headers that
176           WebService::Validator::HTML::W3C relies on so it is likely that
177           there is not a W3C Validator at that URI.  The other possibility is
178           that it didn't like the URI you provided. Sadly the Validator
179           doesn't give very useful feedback on this at the moment.
180
181       Could not contact validator
182           WebService::Validator::HTML::W3C could not establish a connection
183           to the URI.
184
185       Did not get a sensible result from the validator
186           Should never happen and most likely indicates a problem somewhere
187           but on the off chance that WebService::Validator::HTML::W3C is
188           unable to make sense of the response from the validator you'll get
189           this error.
190
191       Result format does not appear to be SOAP|XML
192           If you've asked for detailed results and the reponse from the
193           validator isn't in the expected format then you'll get this error.
194           Most likely to happen if you ask for SOAP output from a validator
195           that doesn't support that format.
196
197       You need to provide a uri, string or file to validate
198           You've passed in a hash ( or in fact more than one argument ) to
199           validate but the hash does not contain one of the three expected
200           keys.
201
202   validator_uri
203           $uri = $v->validator_uri();
204           $v->validator_uri('http://validator.w3.org/check');
205
206       Returns or sets the URI of the validator to use. Please note that you
207       need to use the full path to the validator cgi.
208
209   http_timeout
210           $timeout = $v->http_timeout();
211           $v->http_timeout(10);
212
213       Returns or sets the timeout for the HTTP request.
214

OTHER MODULES

216       Please note that there is also an official W3C module that is part of
217       the W3C::LogValidator distribution. However that module is not very
218       useful outside the constraints of that package.
219       WebService::Validator::HTML::W3C is meant as a more general way to
220       access the W3C Validator.
221
222       HTML::Validator uses nsgmls to validate against the W3Cs DTDs. You have
223       to fetch the relevant DTDs and so on.
224
225       There is also the HTML::Parser based HTML::Lint which mostly checks for
226       known tags rather than XML/HTML validity.
227
228       WebService::Validator::CSS::W3C provides the same functionality as this
229       module for the W3C's CSS validator.
230

IMPORTANT

232       This module is not in any way associated with the W3C so please do not
233       report any problems with this module to them. Also please remember that
234       the online Validator is a shared resource so do not abuse it. This
235       means sleeping between requests. If you want to do a lot of testing
236       against it then please consider downloading and installing the
237       Validator software which is available from the W3C. Debian testing
238       users will also find that it is available via apt-get.
239

BUGS

241       While the interface to the Validator is fairly stable it may be
242       updated. I will endeavour to track any changes with this module so
243       please check on CPAN for new versions if you find things break. Also
244       note that this module is only guaranteed to work with the currently
245       stable version of the validator. It will most likely work with any Beta
246       versions but don't rely on it.
247
248       If in doubt please try and run the test suite before reporting bugs.
249       Note that in order to run tests against the validator service you will
250       need to have a connection to the internet and also set an environment
251       variable called TEST_AUTHOR.
252
253       That said I'm very happy to hear about bugs. All the more so if they
254       come with patches ;).
255
256       Please use http://rt.cpan.org/ for filing bug reports, and indeed
257       feature requests.
258

THANKS

260       To the various people on the code review ladder mailing list who
261       provided useful suggestions.
262
263       Carl Vincent provided a patch to allow for proxy support.
264
265       Chris Dolan provided a patch to allow for custom user agents.
266
267       Matt Ryder provided a patch for support of the explanations in the SOAP
268       output.
269

SUPPORT

271       author email or via http://rt.cpan.org/.
272

AUTHOR

274       Struan Donald <struan@cpan.org>
275
276       <http://www.exo.org.uk/code/>
277
279       Copyright (C) 2003-2008 Struan Donald. All rights reserved.
280

LICENSE

282       This program is free software; you can redistribute it and/or modify it
283       under the same terms as Perl itself.
284

SEE ALSO

286       perl(1).
287
288
289
290perl v5.12.0                      2010-05-07WebService::Validator::HTML::W3C(3)
Impressum