php – DOMDocument :: validate()问题
|
我有一个很大的问题,PHP DOMDocument :: validate()似乎系统地询问了DTD. 当我想验证例如XHTML文档as explained here时,这是一个大问题. 由于w3.org似乎拒绝来自PHP服务器的所有请求,因此使用此方法验证我的文档是不可能的…… 那有什么解决方案吗? 谢谢你提前 [编辑]以下是一些准确性: /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 相关问题: > How to import XML string in a php > http://bugs.php.net/bug.php?id=48080 您可以自己托管DTD并相应地更改systemId,也可以为通过libxml完成的任何加载提供自定义流上下文.例如,提供UserAgent将绕过W3C的阻塞.您也可以通过这种方式添加代理.看到 > 例: $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());
这会输出 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) (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
