Just to add my two cents to the old question, but the most appropriate answer seems to involve using simplexml_load_file ("test.xml"); and then check that the node you expect is not empty. Since this will cause a warning level error if the file is empty, I would not agree and instead turned the call over using the file test.
$xmlInfo = new SplFileInfo('test.xml'); if((int) $xmlInfo->getSize() > 0) { $xml = simplexml_load_file($xmlInfo->getPath()); }
Of course, the OP asked How can I check with PHP if a xml is empty , which does not indicate whether it has a node value or a file, but for completeness it is.
source share