I know there are many examples of creating cdata with php but I have not found one that helps in my situation. I need to create an xml file that will be used by something other than php. I need to create cdata in the xml that will contain a function to be used. The final xml file should look as follows.
<?xml version="1.0" encoding="utf-8" ?>
<component name="Test" extends="out" >
<script type="text" >
<![CDATA[
function init()
m.content = createObject("RoSGNode","ContentNode")
m.top.setFocus(true)
dateNow = CreateObject("roDateTime")
dateNow = dateNow.asSeconds() - 2000
addItemName($Iname)
end function
]]>
</script>
</component>
Code to create the xml. I just don't know how to create cdata info. Any help would be greatly appreciated.
$xml=new DOMDocument('1.0', 'UTF-8');
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
$components = $xml->createElement("components");
$name=$xml->createAttribute("name");
$name->value = "Test";
$extends=$xml->createAttribute("extends");
$extends->value = "out";
$components->appendChild($name);
$components->appendChild($extends);
$script = $xml->createElement("script");
$type=$xml->createAttribute("type");
$type->value = "text";
$script->appendChild($type);
$components->appendChild($script);
$xml->appendChild($components);
$xml->save($filename2);
After little more effort, was able to get cdata in.
$cdata = $xml->createCDATASection("function init()");
$script->appendChild($cdata);