0

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?

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by Venom Rush
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.