tags:

views:

1150

answers:

2

Hey all,

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!

+1  A: 
$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);

:)

nlaq
+2  A: 

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

Fernando Barrocal