I'm using simplexml_load_string to extract a node from an xml filen xml file. It works most of the time, but not all, and when it fails, it gives the error:
"call to a member function xpath() on a non-object"
I suspect it's because the $menuXML isn't fully loaded? It is dynamic, so may change. The code should handle this and simply ignore it until the next time it is analysed.
I did try using libxml_use_internal_errors to try and prevent the exceptions affecting the code, but it didn't work. I could use try/catch, but is there a better way?
snip of code:
$xml = simplexml_load_string($menuXML, null, null, "http://www.w3.org/2001/XMLSchema-instance/");
if ($xml !==FALSE) {
$dump = $xml->xpath('books'); //fails here
}