I use entities in XML and I don\'t understand my results.
I have an XML file wich calls an external entity, this is config.xml :
Yes, this does really look weird. However, you can not use var_dump
or print_r
on a SimpleXMLElement. These elements are with a lot of magic and the var_dump
here is lying to you. I mean really lying, see:
var_dump($config->totalInstances->totalInstances);
Is giving NULL
and no SimpleXMLElement at all.
In your specific case if you want to make use of the document as a SimpleXMLElement
with expanded entities, then you can use the LIBXML_NOENT option (substitute entities):
$config = simplexml_load_file('config.xml', NULL, LIBXML_NOENT);
This does allow to iterate over and access the entities that are represented by the entity/ies. The var_dump
then looks much better, too:
class SimpleXMLElement#4 (1) {
public $totalInstances =>
class SimpleXMLElement#3 (1) {
public $nombre =>
string(2) "45"
}
}