SimpleXML keep html tags and cdata when saving...?

Discussion in 'PHP' started by 123GoToAndPlay, Sep 25, 2009.

  1. #1
    Hi all,

    I have a simpleXML related question, when i save the edited .xml file it doesn't keep the html tags??

    this is part of the edit and save function
    
    function editXMLnode($lang, $xmlNode, $pageTitle, $pageContent) {
    
    	$xmlobj = simplexml_load_file("../assets/xml/content-".$lang."2.xml", 'SimpleXMLElement' , LIBXML_NOCDATA);
    	
    	foreach($xmlobj->xpath("//page[@gotoURL='".$xmlNode."']") as $found) {
    		$found->pageTitle = $pageTitle;
    		$found->pageContent = "<![CDATA[".$pageContent."]]>";
    	}
    	$content = $xmlobj->asXML();
    	
    	file_put_contents("../assets/xml/xml.xml", $content);
    	
    }
    
    Code (markup):
    Any pointers??
     
    123GoToAndPlay, Sep 25, 2009 IP
  2. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ok i solved it by

    
    $content = $xmlobj->asXML();
    $content = str_replace('<pageContent>','<pageContent><![CDATA[',$content);
    $content = str_replace('</pageContent>',']]></pageContent>',$content);
    $content =  html_entity_decode($content);
    
    Code (markup):
     
    123GoToAndPlay, Sep 25, 2009 IP