DOMDocument :: validate () problem

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

This is a big problem when I want to check, for example, an XHTML document as described here .

Since w3.org seems to reject the entire request from the PHP server, it is not possible to validate my document using this method ...

Is there any solution for this?

thanks in advance

[EDIT] The following are some guidelines:

/var/www/test.php:

<?php $implementation = new DOMImplementation(); $dtd = $implementation->createDocumentType ( 'html', // qualifiedName '-//W3C//DTD XHTML 1.0 Transitional//EN', // publicId 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-' .'transitional.dtd' // systemId ); $document = $implementation->createDocument('', '', $dtd); $document->validate(); 

[ http: //] 127.0.0.1/test.php :

 Warning: DOMDocument::validate(http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd): 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 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" in /var/www/test.php on line 14 Warning: DOMDocument::validate(): Could not load the external subset "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" in /var/www/test.php on line 14 

Related questions:

  • How to import XML string in php DOMDocument ? (solved)
+6
xml php xhtml domdocument
source share
1 answer

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

You can host the DTD yourself and change the systemId accordingly, or you can provide a custom thread context for any download executed via libxml. For example, providing a UserAgent will bypass the W3C lock. You can also add proxies this way. Cm.

Example:

 $di = new DOMImplementation; $dom = $di->createDocument( 'html', 'html', $di->createDocumentType( 'html', '-//W3C//DTD XHTML 1.0 Transitional//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' ) ); $opts = array( 'http' => array( 'user_agent' => 'PHP libxml agent', ) ); $context = stream_context_create($opts); libxml_set_streams_context($context); var_dump($dom->validate()); 

This will lead to the conclusion

 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 "http://www.w3.org/1999/xhtml" Warning: DOMDocument::validate(): Value for attribute xmlns of html must be "http://www.w3.org/1999/xhtml" bool(false) 
+8
source share

All Articles