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");

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

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

    // </ad>

// Save xml

Could anyone tell me how I prevent this?

Recommended Answers

You are inserting a text node. DOMDocument has a specific function to create a CDATA section: http://php.net/manual/en/domdocument.createcdatasection.php

Jump to Post

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 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.