使用CDATA的简单XML

时间:2013-09-17 14:16:48

标签: php xml simplexml cdata

我正在尝试使用SimpleXML写入XML,但我需要在我的XML标记中保存html标记。 这是我的代码:

class SimpleXMLExtended extends SimpleXMLElement 
{ 
    public function addCData($cdata_text) 
    { 
        $node= dom_import_simplexml($this); 
        $no = $node->ownerDocument; 
        $node->appendChild($no->createCDATASection($cdata_text)); 
    } 
} 


$xml = new SimpleXMLExtended('<?xml version = "1.0" encoding = "UTF-8"?><xml></xml>'); 

$model->addChild('type')->addCData($type['type']);
$model->addChild('titleXML')->addCData($titleXML['titleXML']);
$model->addChild('features')->addCData($features['features']);
$model->addChild('options')->addCData($options['options']);
$model->addChild('gallery')->addCData($gallery['gallery']);
$model->addChild('info')->addCData($info['info']);

echo('XML: '.$xml->asXML());

我一直收到以下错误:

  

致命错误:在第148行的...... / admin / addprocess.php中的非对象上调用成员函数addChild()

想法?

0 个答案:

没有答案
相关问题