I have this xml (had to cut/paste via HTML).
<tr>
<td>http://www.example.co.uk/the-view-from-22/feed/</td>
<td>Example Blogs » The View from 22 » Example Blogs</td>
<td>http://blogs.example.co.uk/</td>
<td><![CDATA[Listen: The Example’s verdict on the debate]]></td>
<td>http://blogs.example.co.uk/coffeehouse/2015/04/podcast-special-the-debate/</td>
</tr>
It is being loaded in to an XML dom document
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML( $xml->asXML() );
return $dom->saveXML();
But this throws an error about the ’ entity not being defined.
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Entity 'rsquo' not defined in Entity,...
As it is in a CDATA section I expected the DOMDocument to treat it as text and ignore it... but it doesn't... is there a way around this?
The Data is being pulled directly out of a mysql database in a view, so there isn't much scope for 'fixing it up' first - I added the CDATA in the select clause for the view, that was my attempt at a fix!
edit Traced it back following suggestions below (cheers!)
The data is being loaded using $xml->addChild( $key, $value ) but the $value is in the form so is being encoded as you surmised.
So am just trying this...
How to write CDATA using SimpleXmlElement?
And it works - I am now loading up the orignal doc with:-
if (strpos(strtoupper($value),'<![CDATA[') === 0 && strpos(strrev($value),'>]]') === 0) {
$child = $xml->addChild( $key );
$node = dom_import_simplexml($child);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection(substr($value,9,strlen($value)-12)));
//simple key/value child pair
} else {
$xml->addChild( $key, $value );
}