1WebService::Validator::UHsTeMrL:C:oWn3tCr(i3b)uted PerlWDeobcSuemrevnitcaet:i:oVnalidator::HTML::W3C(3)
2
3
4
6 WebService::Validator::HTML::W3C - Access the W3Cs online HTML
7 validator
8
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
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
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 compatibility 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 warningcount
125 $num_errors = $v->warningcount();
126
127 Returns the number of warnings that the validator encountered.
128
129 errors
130 $errors = $v->errors();
131
132 foreach my $err ( @$errors ) {
133 printf("line: %s, col: %s\n\terror: %s\n",
134 $err->line, $err->col, $err->msg);
135 }
136
137 Returns an array ref of WebService::Validator::HTML::W3C::Error
138 objects. These have line, col and msg methods that return a line
139 number, a column in that line and the error that occurred at that
140 point.
141
142 Note that you need XML::XPath for this to work and you must have
143 initialised WebService::Validator::HTML::W3C with the detailed option.
144 If you have not set the detailed option a warning will be issued, the
145 detailed option will be set and a second request made to the validator
146 in order to fetch the required information.
147
148 If there was a problem processing the detailed information then this
149 method will return 0.
150
151 warnings
152 $warnings = $v->warnings();
153
154 Works exactly the same as errors only returns an array ref of
155 WebService::Validator::HTML::W3C::Warning objects. In all other
156 respects it's the same.
157
158 validator_error
159 $error = $v->validator_error();
160
161 Returns a string indicating why validation may not have occurred. This
162 is not the reason that a webpage was invalid. It is the reason that no
163 meaningful information about the attempted validation could be
164 obtained. This is most likely to be an HTTP error
165
166 Possible values are:
167
168 You need to supply a URI to validate
169 You didn't pass a URI to the validate method
170
171 You need to supply a URI with a scheme
172 The URI you passed to validate didn't have a scheme on the front.
173 The W3C validator can't handle URIs like www.example.com but
174 instead needs URIs of the form http://www.example.com/.
175
176 Not a W3C Validator or Bad URI
177 The URI did not return the headers that
178 WebService::Validator::HTML::W3C relies on so it is likely that
179 there is not a W3C Validator at that URI. The other possibility is
180 that it didn't like the URI you provided. Sadly the Validator
181 doesn't give very useful feedback on this at the moment.
182
183 Could not contact validator
184 WebService::Validator::HTML::W3C could not establish a connection
185 to the URI.
186
187 Did not get a sensible result from the validator
188 Should never happen and most likely indicates a problem somewhere
189 but on the off chance that WebService::Validator::HTML::W3C is
190 unable to make sense of the response from the validator you'll get
191 this error.
192
193 Result format does not appear to be SOAP|XML
194 If you've asked for detailed results and the reponse from the
195 validator isn't in the expected format then you'll get this error.
196 Most likely to happen if you ask for SOAP output from a validator
197 that doesn't support that format.
198
199 You need to provide a uri, string or file to validate
200 You've passed in a hash ( or in fact more than one argument ) to
201 validate but the hash does not contain one of the three expected
202 keys.
203
204 validator_uri
205 $uri = $v->validator_uri();
206 $v->validator_uri('http://validator.w3.org/check');
207
208 Returns or sets the URI of the validator to use. Please note that you
209 need to use the full path to the validator cgi.
210
211 http_timeout
212 $timeout = $v->http_timeout();
213 $v->http_timeout(10);
214
215 Returns or sets the timeout for the HTTP request.
216
218 Please note that there is also an official W3C module that is part of
219 the W3C::LogValidator distribution. However that module is not very
220 useful outside the constraints of that package.
221 WebService::Validator::HTML::W3C is meant as a more general way to
222 access the W3C Validator.
223
224 HTML::Validator uses nsgmls to validate against the W3Cs DTDs. You have
225 to fetch the relevant DTDs and so on.
226
227 There is also the HTML::Parser based HTML::Lint which mostly checks for
228 known tags rather than XML/HTML validity.
229
230 WebService::Validator::CSS::W3C provides the same functionality as this
231 module for the W3C's CSS validator.
232
234 This module is not in any way associated with the W3C so please do not
235 report any problems with this module to them. Also please remember that
236 the online Validator is a shared resource so do not abuse it. This
237 means sleeping between requests. If you want to do a lot of testing
238 against it then please consider downloading and installing the
239 Validator software which is available from the W3C. Debian testing
240 users will also find that it is available via apt-get.
241
243 While the interface to the Validator is fairly stable it may be
244 updated. I will endeavour to track any changes with this module so
245 please check on CPAN for new versions if you find things break. Also
246 note that this module is only guaranteed to work with the currently
247 stable version of the validator. It will most likely work with any Beta
248 versions but don't rely on it.
249
250 If in doubt please try and run the test suite before reporting bugs.
251 Note that in order to run tests against the validator service you will
252 need to have a connection to the internet and also set an environment
253 variable called TEST_AUTHOR.
254
255 That said I'm very happy to hear about bugs. All the more so if they
256 come with patches ;).
257
258 Please use <http://rt.cpan.org/> for filing bug reports, and indeed
259 feature requests. The code can also be found on github
260 <https://github.com/struan/webservice-validator-html-w3c>.
261
263 To the various people on the code review ladder mailing list who
264 provided useful suggestions.
265
266 Carl Vincent provided a patch to allow for proxy support.
267
268 Chris Dolan provided a patch to allow for custom user agents.
269
270 Matt Ryder provided a patch for support of the explanations in the SOAP
271 output.
272
274 author email or via <http://rt.cpan.org/>.
275
277 Struan Donald <struan@cpan.org>
278
279 <http://www.exo.org.uk/code/>
280
282 Copyright (C) 2003-2008 Struan Donald. All rights reserved.
283
285 This program is free software; you can redistribute it and/or modify it
286 under the same terms as Perl itself.
287
289 perl(1).
290
291
292
293perl v5.34.0 2022-01-21WebService::Validator::HTML::W3C(3)