Services_W3C_HTMLValidator

なんか、世の中にあるWebサービスがどんどん揃っていきますね。。。> PEAR
まだ0.2.0αですが試してみました。ざっと次のような感じで書けますね。
<?php
require_once 'Services/W3C/HTMLValidator.php';
?>
<?php
$validator = new Services_W3C_HTMLValidator();
// ファイルから検証
$ret = $validator->validateFile('example.html');
// URLから検証
//$ret = $validator->validate('http://www.example.com/');
/**
* 結果オブジェクトのうち、エラーを一覧表示する
*
* $ret :Services_W3C_HTMLValidator_Responseオブジェクト
* $error:Services_W3C_HTMLValidator_Errorオブジェクト
*/
foreach ($ret->errors as $error) {
printf('<li>[%d:%d] %s', $error->line, $error->col, $error->message);
}
?>あと、ドキュメントフラグメントから検証を行うvalidateFragmentメソッドや、parseSOAP12Responseメソッドも用意されています。で、何でparseSOAP12Responseメソッドが用意されてるのかな?と思ったら、検証のレスポンスをSOAP1.2形式で受け取るようなリクエストを投げているためでした。内部的にはPEAR::HTTPRequestを使ってリクエストを投げています。以下は、HTMLValidator.phpの抜粋です。
class Services_W3C_HTMLValidator
{
:
/**
* Output format
*
* Triggers the various outputs formats of the validator. If unset, the usual
* Web format will be sent. If set to soap12, the SOAP1.2 interface will be
* triggered. See below for the SOAP 1.2 response format description.
*/
public $output = 'soap12';
:
/**
* Prepares a request object to send to the validator.
*
*/
protected function buildRequest($type = 'uri')
{
:
foreach (array( 'charset',
'fbc',
'doctype',
'fbd',
'verbose',
'ss',
'outline',
'output') as $option) {
if (isset($this->$option)) {
if (is_bool($this->$option)) {
$this->request->$method($option, intval($this->$option));
} else {
$this->request->$method($option, $this->$option);
}
}
}
:
}ちなみに、レスポンスの形式についてはUser Documentation for The W3C Markup Validatorに書いてありました。RDF形式でも受け取れるのか。。。へぇ〜。