DOMDocument::validate() problem DOMDocument::validate() problem xml xml

DOMDocument::validate() problem


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

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 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 "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)