Writing CDATA in XML output ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • usenet@isotopeREEMOOVEmedia.com

    #1

    Writing CDATA in XML output ?

    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("even ts");
    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_se ction, 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 !

  • Janwillem Borleffs

    #2
    Re: Writing CDATA in XML output ?

    usenet@isotopeR EEMOOVEmedia.co m wrote:[color=blue]
    > I've seen the short manual page about create_cdata_se ction, 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 ![/color]

    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_s ection($details );
    $record->append_child($ cdata);
    ....


    JW

    Comment

    • usenet@isotopeREEMOOVEmedia.com

      #3
      Re: Writing CDATA in XML output ?

      On Mon, 17 Jan 2005 10:16:58 +0100, Janwillem Borleffs <jw@jwscripts.c om> wrote:
      [color=blue]
      >usenet@isotope REEMOOVEmedia.c om wrote:[color=green]
      >> I've seen the short manual page about create_cdata_se ction, 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 ![/color]
      >
      >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_s ection($details );
      > $record->append_child($ cdata);
      >...
      >
      >
      >JW[/color]

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

      This is a huge help -- thanks so much.

      Comment

      Working...