I am using the CakePHP XmlHelper to parse XML files like:
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
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
$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);
:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.