I am using simplexml_load_file to parse an XML file that must follow a DTD. Both XML and DTD are local files.
$obj_xml = simplexml_load_file(
$str_xml_file,
'SimpleXMLElement',
LIBXML_DTDVALID + LIBXML_NOENT
);
if (false === $obj_xml) {
throw new Exception("XML file is not valid");
}
The XML file is something like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapping SYSTEM 'mapping.dtd' [
<!ENTITY data_file "data.csv">
]>
<mapping>
...
</mapping>
I was under the impression that if the XML was not valid according to the DTD specified then simplexml_load_file would return false but it doesn't. I have also tried checking if $obj_xml is an instance of the LibXMLError class, but same result.
It seems the DTD is totally ignored by simplexml_load_file. I have tried changing its name, to somethin non-existing, and still no error.
As I said, both the XML and DTD are local files. $str_xml_file is the absolute full pathname of the XML file and the DTD resides in the same directory.