codeinphp Posted August 13, 2016 Share Posted August 13, 2016 I need to create an xml file with php. Most of the xml is no problem, but part of it has cdata with other information. Following is how the output should look <?xml version="1.0" encoding="utf-8" ?> <component name="customEPGGrid" extends="EPGGrid" > <script type="text/brightscript" > <![CDATA[ function init() print "inside epg" m.content = createObject("RoSGNode","ContentNode") m.top.setFocus(true) dateNow = CreateObject("roDateTime") dateNow = dateNow.asSeconds() - 2000 addChannel("ABC") addItem("ABC Show ", dateNow) m.top.content = m.content m.top.translation = [50, 300] m.top.numRows = 5 m.top.duration = 10800 m.top.nowNextMode = false m.top.infoGridGap = 0 m.top.channelInfoColumnLabel = "Hello" end function ]]> </script> </component> $xml=new DOMDocument('1.0', 'UTF-8'); $xml->preserveWhiteSpace = false; $xml->formatOutput = true; $components = $xml->createElement("components"); $name=$xml->createAttribute("name"); $name->value = "customEPGGrid"; $extends=$xml->createAttribute("extends"); $extends->value = "EPGGrid"; $components->appendChild($name); $components->appendChild($extends); $script = $xml->createElement("script"); $type=$xml->createAttribute("type"); $type->value = "text/brightscript"; $cdata = $xml->createCDATASection("function init()"); $script->appendChild($cdata); $script->appendChild($type); $components->appendChild($script); $xml->appendChild($components); $xml->save($filename2); Here is the php code that creates the xml. I can create the cdata element and the Function Int(), but not sure how to get the rest. Any help in gettig the information in the function int() would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/301884-creating-cdata/ Share on other sites More sharing options...
Solution Jacques1 Posted August 13, 2016 Solution Share Posted August 13, 2016 What exactly is the problem? As far as I can tell, the function definition is just hard-coded text, so all you have to do is put that text into a string (preferrably with a nowdoc): $cdata = $xml->createCDATASection(<<<'INIT_DEF' function init() print "inside epg" m.content = createObject("RoSGNode","ContentNode") m.top.setFocus(true) dateNow = CreateObject("roDateTime") dateNow = dateNow.asSeconds() - 2000 addChannel("ABC") addItem("ABC Show ", dateNow) m.top.content = m.content m.top.translation = [50, 300] m.top.numRows = 5 m.top.duration = 10800 m.top.nowNextMode = false m.top.infoGridGap = 0 m.top.channelInfoColumnLabel = "Hello" end function INIT_DEF ); 1 Quote Link to comment https://forums.phpfreaks.com/topic/301884-creating-cdata/#findComment-1536115 Share on other sites More sharing options...
codeinphp Posted August 13, 2016 Author Share Posted August 13, 2016 Thanks, not knowing alot about php, this really helped. Quote Link to comment https://forums.phpfreaks.com/topic/301884-creating-cdata/#findComment-1536116 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.