I am new to PHP and I am trying to read the output of an XML file that resides on a folder on my local box. In the PHP.net/simplexml_load_file tutorial the following LIKE code should show the SimpleXMLElement Object when I do a print_r($xml). But when I run the script on my local terminal I get the file path:
/Users/msavoy/XMLSourceDir/sfly-6×8.000020513524-7001536_28935-tb.33.xml
I need to be able to get the $xml object so that I can display all the elements within the object.
Here is my code:
// Get the correct count of the values in the $sourceXmlDir after the unset function completes
$sourceXmlArray = array_values($sourceXmlDir);
$count_xml_files = count($sourceXmlArray);
// Check to ensure that there are xml files in the directory before processing parsing the file
// If no files exist create an Exception and log the error.
if ($count_xml_files > 0) {
// Cycle through the XML files in the $sourceXmlArray
for ($i = 0; $i < $count_xml_files; $i++) {
$xml = ($sourceDir . '/' . $sourceXmlArray[$i]);
print_r($xml);
}
} else {
$error_output = date('Y-m-d H:i:s') . 'There are no XML files in the source directory: ' . $sourceDir;
error_log(date('Y-m-d H:i:s') . 'There are no XML files in the source directory: ' . $sourceDir);
throw new Exception($error_output);
}
What am I missing? Any help/direction would be appreciated. Regards.
You didn’t actually call
simplexml_load_file, so why would$xmlbe aSimpleXMLElementobject?Try this: