I'm trying to create an xml document without converting html entities but when I create and save the file with DOMDocument the < and > characters are converted to &lt; and &gt; so trying to wrap copy within <![CDATA[]]> is proving problematic.

Example of my code below:

// Initiate the XML
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;

$r = $doc->createElement("advertising");
$doc->appendChild($r);

    // <ad>
    $ad = $doc->createElement('ad');

        // <TITLE>
        $title = $doc->createElement('TITLE');
        $title->appendChild($doc->createTextNode('<![CDATA['.$v_title.']]>'));
        $ad->appendChild($title);

    // </ad>
    $r->appendChild($ad);

// Save xml
$doc->saveXML();
$doc->save('ads.xml');

Could anyone tell me how I prevent this?

Recommended Answers

All 2 Replies

Hi pritaeas

Thanks. I happened to find it a couple of minutes ago ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.