DOMDocument::validate() problem

I have a big problem with the PHP DOMDocument::validate() who seems to ask the DTD systematically.

It is a big problem when I whant to validate, for example, an XHTML document as explained here.

As seems to reject all request from a PHP server, it’s impossible to validate my document with this method…

Is there any solution for that ?

Thanks by advance

[EDIT] Here is some precisions :

/var/www/test.php :

$implementation = new DOMImplementation();

$dtd = $implementation->createDocumentType
         'html',                                     // qualifiedName
         '-//W3C//DTD XHTML 1.0 Transitional//EN',   // publicId
           .'transitional.dtd'                       // systemId

$document = $implementation->createDocument('', '', $dtd);


[http://] :

Warning: DOMDocument::validate( failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
 in /var/www/test.php on line 14

Warning: DOMDocument::validate(): I/O warning : failed to load external entity "" in /var/www/test.php on line 14

Warning: DOMDocument::validate(): Could not load the external subset "" in /var/www/test.php on line 14

Related question :


Like pointed out in the comments, there is a Bug/FeatureRequest for DOMDocument::validate to accept the DTD as a string:

You could host the DTD yourself and change the systemId accordingly or you can provide a custom stream context to any loading done through libxml. For instance, providing a UserAgent will get around the W3C’s blocking. You could also add proxy this way. See


$di = new DOMImplementation;
$dom = $di->createDocument(
        '-//W3C//DTD XHTML 1.0 Transitional//EN',
$opts = array(
    'http' => array(
        'user_agent' => 'PHP libxml agent',
$context = stream_context_create($opts);


This would output

Warning: DOMDocument::validate(): Element html content does not follow the DTD, expecting (head , body), got  

Warning: DOMDocument::validate(): Element html namespace name for default namespace does not match the DTD 

Warning: DOMDocument::validate(): Value for attribute xmlns of html is different from default "" 

Warning: DOMDocument::validate(): Value for attribute xmlns of html must be ""