I am trying to read an XML file and it returns “failed to load”. Please let me know what mistake I am making here. Its a pure simple program. I did it from localhost and with my public host, the XML file and the PHP file both are in the same location.
<?php
$xml = simplexml_load_file('xml01.xml') or die("Failed to load");
echo $xml->event[0]->eventId;
?>
This is my XML file saved as "xml01.xml"in the same location as the above PHP :
This function may return Boolean FALSE , but may also return a non-Boolean value which evaluates to FALSE . Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.
Thanks It works. The problem was (I guess), my XML had an element which is a URL and its a big file having 10 elements each with around 100 records.
Do you think if an XML has a URL as an element, which will cause problems in loading using “simplexml_load_file” ?
Thank you.
AFAIK, XML elements can be just about anything, but I’ve never seen one like <http://example.com>something</http://example.com>. I’m assuming that would not be valid XML and could indeed be a problem. I wouldn’t know how to even begin doing that.
If you mean value eg. <resource>http://example.com</resource> I don’t think that would cause any problems in terms of valid XML
My XML file was just like your 2nd node and therefore it should not cause any issues. Anyhow, I will try with a simple XML with just 5 records with a URL and see how it works. Thanks for the information. Appreciated.