By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Writing CDATA in XML output ?

P: n/a
I'm utterly confounded, and can only find info on parsing CDATA _from_ an XML
file, not _writing_ CDATA in XML formatted output.
---------------------------------
What I am currently generating :
<events>
<day thedate="15/10/2004" text1="var1" text2="var2" /></day>
. . .
</events>
---------------------------------
What I need to generate (word wrap aside) :
<events>
<day thedate="15/10/2004" text1="var1" text2="var2" /><![CDATA[
$details_field_here ]]></day>
. . .
</events>
---------------------------------
I can't figure out how to take the MySQL field containing HTML and insert it
into a CDATA segment as required.
---------------------------------

The code I have so far :

$root = $doc->add_root("events");
while (list($thedate, $var1, $var2, $details) = mysql_fetch_row($result)) {
$record = $root->new_child("day", "");
$record->set_attribute("thedate", $thedate);
$record->set_attribute("text1", $var1);
$record->set_attribute("text2", $var2);
// Stuck here, trying to insert $details CDATA
}

I've seen the short manual page about create_cdata_section, but nothing that's
actually helpful. I must be missing something in all my Googling and
manual-reading, but I'm stumped.

Any and all advice will be greatly appreciated. TIA !

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
us****@isotopeREEMOOVEmedia.com wrote:
I've seen the short manual page about create_cdata_section, but nothing that's
actually helpful. I must be missing something in all my Googling and
manual-reading, but I'm stumped.

Any and all advice will be greatly appreciated. TIA !


Untested, but this should do it:

....
$record = $root->new_child("day", "");
$record->set_attribute("thedate", $thedate);
$record->set_attribute("text1", $var1);
$record->set_attribute("text2", $var2);
// Add $details CDATA
$cdata = $doc->create_cdata_section($details);
$record->append_child($cdata);
....
JW

Jul 17 '05 #2

P: n/a
On Mon, 17 Jan 2005 10:16:58 +0100, Janwillem Borleffs <jw@jwscripts.com> wrote:
us****@isotopeREEMOOVEmedia.com wrote:
I've seen the short manual page about create_cdata_section, but nothing that's
actually helpful. I must be missing something in all my Googling and
manual-reading, but I'm stumped.

Any and all advice will be greatly appreciated. TIA !


Untested, but this should do it:

...
$record = $root->new_child("day", "");
$record->set_attribute("thedate", $thedate);
$record->set_attribute("text1", $var1);
$record->set_attribute("text2", $var2);
// Add $details CDATA
$cdata = $doc->create_cdata_section($details);
$record->append_child($cdata);
...
JW


Thanks, JW ! That's exactly right. I didn't realize that append_child was
necessary here.

This is a huge help -- thanks so much.

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.