PHP SimpleXML CData not loading + solution

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

The php simpleXML object is my preferred way of working with XML, but it has some unusual quirks that can drive you up the wall. One of these is that, by default, it will not read CDATA within an XML file, and will just leave the node blank.

If you need to access this data then create your xml object like this

$xmlFile = “/path/to/xml/file.xml”; if (file_exists($xmlFile)) { $xml = simplexml_load_file($xmlFile,‘SimpleXMLElement’, LIBXML_NOCDATA); echo $xml->cDataNode; }


Tags: phpproblemxmlsolutiondebuggingsimplexml