simplexml_load_string and simplexml_load_file are buggy and don't work well on XML with a complex markup.
I tried both functions to parse some VALID XML SOAP responses and could not even get an error message.
I had to use DOMDocument instead (worked like a charm).
Here is how we suppose to check simplexml for errors (if you are lucky to see errors, not just "false" returned from function)
libxml_use_internal_errors(true);
$xml=simplexml_load_string($myXMLData); //or simplexml_load_file
foreach( libxml_get_errors() as $error ) {
print_r($error);
}
Answer from vitaly goji on Stack OverflowVideos
simplexml_load_string and simplexml_load_file are buggy and don't work well on XML with a complex markup.
I tried both functions to parse some VALID XML SOAP responses and could not even get an error message.
I had to use DOMDocument instead (worked like a charm).
Here is how we suppose to check simplexml for errors (if you are lucky to see errors, not just "false" returned from function)
libxml_use_internal_errors(true);
$xml=simplexml_load_string($myXMLData); //or simplexml_load_file
foreach( libxml_get_errors() as $error ) {
print_r($error);
}
I could find an answer to my question with a small workaround. simplexml_load_string() continuously displayed encoding errors. So I used simplexml_load_file() as bellow. I've saved the file in to local location and then load with simplexml_load_file().
$tempLocalPath = "temp/data.xml";
file_put_contents($tempLocalPath, $s3Data);
$xml = simplexml_load_file($tempLocalPath);
However still I don't understan why simplexml_load_string() couldn't parse the same thing.