脚本宝典收集整理的这篇文章主要介绍了php – DOMDocument :: validate()问题,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
当我想验证例如XHTML文档as explained here时,这是一个大问题.
由于w3.org似乎拒绝来自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();
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
相关问题:
> http://bugs.php.net/bug.php?id=48080
您可以自己托管DTD并相应地更改systemId,也可以为通过libXMl完成的任何加载提供自定义流上下文.例如,提供UserAgent将绕过W3C的阻塞.您也可以通过这种方式添加代理.看到
> libxml_set_streams_context()
和
> list of available HTTP context options
例:
$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)
以上是脚本宝典为你收集整理的php – DOMDocument :: validate()问题全部内容,希望文章能够帮你解决php – DOMDocument :: validate()问题所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。