1 Vote Vote

getting cdata (html) in a dom xml element

Posted by topdog 283 days ago Questions| cdata html element All

I am creating an XML document with DOM and got HTML funny characters like ä and å from a database that i need to put inside an element. But i can't get it to work really.

What is the proper way to add CDATA HTML in an element so that my output becomes like this:

<TRANSLATIONS>
    <DENMARK>
        <ERRORADDRESSLINE1REQUIRED><![CDATA[&auml; &aring;]]></ERRORADDRESSLINE1REQUIRED>
    </DENMARK>
</TRANSLATIONS>

using this:

$sData = "<![CDATA[" . $value . "]]>";
$objLabel = $objXmlDoc->createElement($label, $sData);

doesn't really do the trick and appending $objXmlDoc->createCDATASection($value) creates an element next to another label and not inside a label.

What do i overlook?

Originally asked by: half-a-nerd on Stack Overflow

Discuss Bury


Who Voted for this Question