Can't add CDATA into my XML string using simplexml with php

TeliweraGrete

New Member
I'm simply wanting to add cdata to an xml node - description. My xml function is below. I have tried using bits of the following function on php.net in my function\[code\]function updateXMLFile($itemName,$description,$pageName,$imageFileName){ $imageSrc="http://stackoverflow.com/questions/10445696/<img src='http://nicolaelvin.com/authoring/phpThumb/phpThumb.php?src=http://stackoverflow.com/questions/images/".$imageFileName."&w=100'/>"; $id=strtolower($id=str_replace(' ','_',$itemName)); $directLinkToItem='http://nicolaelvin.com/authoring/'.$pageName.'.php#'.$id; $xml = simplexml_load_file('nicolaElvinsPortfolio.xml'); $item = $xml->channel->addChild('item'); $item ->addChild('title',$itemName); $item->addChild('pubDate',date('r')); $item->addChild('link', $directLinkToItem); $item->addChild('description'); $cdata->description->createCDATASection('testyfhgjhsgsdjahgs'); $item->appendChild($cdata); ///Format XML to save indented tree rather than one line $dom = new DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xml->asXML()); //Save XML to file - remove this and following line if save not desired $dom->save('nicolaElvinsPortfolio.xml');}//function from php.netfunction sxml_cdata($path, $string){ $dom = dom_import_simplexml($path); $cdata = http://stackoverflow.com/questions/10445696/$dom->ownerDocument->createCDATASection($string); $dom->appendChild($cdata);}\[/code\]
diV76.png
 
Back
Top