Jump to content

Creating cdata


codeinphp
Go to solution Solved by Jacques1,

Recommended Posts

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.

Link to comment
Share on other sites

  • Solution

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
);
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.