简体   繁体   English

如何使用CakePHP APP类从URL加载XML文件?

[英]How can I use the CakePHP APP class to load XML files from a URL?

I am using the CakePHP XmlHelper to parse XML files like: 我正在使用CakePHP XmlHelper来解析XML文件,例如:

App::import('Xml');
$file = "my_xml_file.xml";
$parsed_xml =& new XML($file);

How can I use it to load XML files from URLs like http://www.site.com/file.xml 如何使用它从诸如http://www.site.com/file.xml之类的 URL加载XML文件

Thanks! 谢谢!

It's simple 这很简单

App::import('Xml');
$url = "http://www.example.com/xml_file.xml";
$parsed_xml =& new XML($url);

Just using the URL instead of the file, Cake will internally choose the way to open the file 仅使用URL而不是文件,Cake将在内部选择打开文件的方式

$contents = file_get_contents("http://www.site.com/file.xml");
$file = fopen("temp.xml", "rb");
fwrite($file, $contents);
fclose($file);
unset($contents)

App::import('Xml');
$file = "temp.xml";
$parsed_xml =& new XML($file);

:) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM