PHP头条
热点:

phpsimpleXML添加CDATA格式数据


我们知道php中的simpleXML没办法直接很方便的添加CDATA格式的数据,这样对我们操作时会有一定的问题,下面我来给各位同学介绍php simpleXML添加CDATA格式数据一种办法,php实例代码如下:

   instead of Site Title 
* 
*/ 
class SimpleXMLExtended extends SimpleXMLElement 
{ 
    public function addCData($cdata_text) 
    { 
        $node = dom_import_simplexml($this); 
        $no   = $node->ownerDocument; 
        $node->appendChild($no->createCDATASection($cdata_text)); 
    } 
}
$xmlFile    = 'config.xml'; 
// instead of $xml = new SimpleXMLElement(''); 
$xml = new SimpleXMLExtended(''); 
$site = $xml->addChild('site'); 
// instead of $site->addChild('site', 'Site Title'); 
$site->title = NULL; // VERY IMPORTANT! We need a node where to append 
$site->title->addCData('Site Title'); 
$site->title->addAttribute('lang', 'en'); 
$xml->asXML($xmlFile);

www.phpzy.comtrue/phpyy/48325.htmlTechArticlephpsimpleXML添加CDATA格式数据 我们知道php中的simpleXML没办法直接很方便的添加CDATA格式的数据,这样对我们操作时会有一定的问题,下面我来给各位同学介绍php simpleXML添加CDATA格式数据一种办...

相关文章

PHP之友评论

今天推荐