Page 1 of 1

Cannot read XML file

Posted: Wed Jan 31, 2018 9:41 am
by mbratu74
I have a php file called from html page. this file need to read a local xml file and return an array with data...
I tried many version of code but when i tried to open the file the page go in error without the possibility to check the error. The only command that work is $xml_string= file_get_contents('Stations.xml');
Any other like :
simplexml_load_string($xml_string);
simplexml_load_file("Stations.xml");
does not work...

The flag allow_open_url is ON...

Someone have an idea about what is happened...

Thanks in advance

Re: Cannot read XML file

Posted: Wed Jan 31, 2018 10:46 am
by Christopher
Where is the file "Stations.xml"? The could should probably be:

Code: Select all

simplexml_load_file('/full/file_system/path/to/Stations.xml');
* replace '/full/file_system/path/to/' with the actual path to the directory containing the XML file.

Re: Cannot read XML file

Posted: Tue Feb 06, 2018 1:48 am
by pardeeptrivedi
<?php
// The file test.xml contains an XML document with a root element
// and at least an element /[root]/title.

if (file_exists('test.xml')) {
$xml = simplexml_load_file('test.xml');

print_r($xml);
} else {
exit('Failed to open test.xml.');
}
?>