FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Adding a CDATA section
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Adding a CDATA section [message #173555] Mon, 18 April 2011 19:33 Go to previous message
JustWondering is currently offline  JustWondering
Messages: 9
Registered: April 2011
Karma:
Junior Member
I am trying to add a CDATA section to a DOMdocument.

Code:

<?php
// Create a DOMDocument object and set nice formatting
$doc = new DOMDocument( "1.0", "UTF-8" );
$doc->formatOutput = true;

// Create the root "stockList" element
$stockList = $doc->createElement( "stockList" );
$doc->appendChild( $stockList );

// Create the first "item" element (apple)
$item = $doc->createElement( "item" );
$item->setAttribute( "type", "fruit" );
$stockList->appendChild( $item );

// Create the item's "description" child element
$description = $doc->createElement( "description" );
$item->appendChild( $description );
$cdata = $doc->createCDATASection( "Apples are <b>yummy</b>" );
$description->appendChild( $cdata );

// Create the second "item" element (beetroot)
$item = $doc->createElement( "item" );
$item->setAttribute( "type", "vegetable" );
$stockList->appendChild( $item );

echo $doc->saveXML();
?>

What I'm expecting to see is Apples are yummy, with yummy in bold.
Here's what I get:

yummy]]>

Firebug / Edit gives me this:

<stocklist>
<item type="fruit">
<description><!--[CDATA[Apples are <b-->yummy]]&gt;</description>
</item>
<item type="vegetable">
</item></stocklist>

What I'm expecting is:

<stocklist>
<item type="fruit">
<description><![CDATA[Apples are <b->yummy</b>]]></description>
</item>
<item type="vegetable">
</item></stocklist>

Any ideas?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Using exec with & - what might I get back?
Next Topic: php sessions and css file?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 17:22:26 GMT 2024

Total time taken to generate the page: 0.05004 seconds