Search the blog

I was recently parsing an XML file from a third-party API and found if any tags had CDATA in the contents (e.g. HTML content) it was returning empty. Thankfully, the fix is easy: just pass the LIBXML_NOCDATA flag to simplexml_load_string.

$xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
Tim Bennett is a web designer and developer. He has a First Class Honours degree in Computing from Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.