开发者

What would cause DOMDocument.load to fail loading XML from a URL that is accessible?

$doc = new DOMDocument();
if ($doc->load('http://foo.com/bar.xml')) {
  // good
} else {
  // wtf happened?
}

I can wget http://foo.com/bar.xml from the location where the PHP code is running, so I know the URL is accessible. I'm think开发者_高级运维ing it must be something other than an HTTP error.

I'm not sure what else could be causing the failure. Maybe a parsing issue? The XML appears to be valid (and passes W3C's validation test). As far as I can tell from the documentation, there's no way to determine why the load failure occurred.

Here's the XML:

 <response> 
  <version>8</version> 
  <minversion>1</minversion> 
  <url>api.asp?</url> 
 </response>


I finally narrowed it down to a PHP configuration setting called allow_url_fopen, which was set to Off on the server running the script.

I modified the php.ini file to enable this setting:

allow_url_fopen = On

And now DOMDocument.load can load XML from a remote URL.

WARNING: apparently there are some security issues with keeping this setting on permanently.


Add this:

    libxml_use_internal_errors ( true );
    $doc = new DOMDocument();
    $doc -> recover = true;
    $doc -> strictErrorChecking = false;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜