从Google App Engine for PHP加载远程XML [英] Load remote XML from Google App Engine for PHP

查看:139
本文介绍了从Google App Engine for PHP加载远程XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从第三方服务器加载远程和动态的XML文件到我的GAE-PHP应用程序中:

  $ itemId = 5; 
$ uri =http://www.myserver.com/getInfoItem.php?itemId={$itemId}&format=xml;

我试图使用simplexml_load_file函数加载XML信息:

  if($ xmlItem = simplexml_load_file($ uri)){
//处理XML信息的代码
}

但是这会导致这个错误:

  PHP警告:simplexml_load_file():I / O警告:未能加载外部实体...

因此,我更改了代码,并尝试将XML加载为通用文本文件。这样,它就能按预期工作:

  if($ fileContents = file_get_contents($ uri)){
$ xmlItem = simplexml_load_string($ fileContents);
//处理XML信息的代码
}

我在想两个函数使用相同的 http wrapper 来获取远程内容,但这似乎不是以这种方式工作。我也查看了GAE 网址提取文档。



我的问题是:为什么第一种方法不起作用?我错过了什么?

解决方案

默认情况下,我们已禁用外部实体的自动加载,您必须选择加入。

 libxml_disable_entity_loader(false); 

。这在禁用功能一节中有详细介绍



这涉及一个额外的步骤:首先,您必须创建一个 php.ini 文件,其中包含此line:

  google_app_engine.enable_functions =libxml_disable_entity_loader


I want to load a remote and dynamic XML file from a third party server into my GAE-PHP application:

$itemId = 5;
$uri = "http://www.myserver.com/getInfoItem.php?itemId={$itemId}&format=xml";

I have tried to load the XML information using the simplexml_load_file function:

if ($xmlItem = simplexml_load_file($uri)) {
  // Code dealing with the XML info
}

But that leads always to this error:

PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "..."

So, I have changed the code and I try load the XML as a generic text file. This way, it works as expected:

if ($fileContents = file_get_contents($uri)) {
  $xmlItem = simplexml_load_string($fileContents);
  // Code dealing with the XML info
}

I was thinking the two functions get the remote contents using the same http wrapper, but that does not seem to work this way. I have had a look to to the GAE URL Fetch documentation, too.

My question is: Why the first approach does not work? Am I missing something?

解决方案

We've disabled automatic loading of external entities by default, you have to opt in.

Try putting

libxml_disable_entity_loader(false);

before you're call. This is documented in the Disabled Functions section

This involves one additional step: First, you must create a php.ini file containing this line:

google_app_engine.enable_functions = "libxml_disable_entity_loader"

这篇关于从Google App Engine for PHP加载远程XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆