‘不允许序列化’SimpleXMLElement’错误插入会话xml值

参见英文答案 > Forcing a SimpleXML Object to a string,regardless of context10个
大家好我有一个在codeigniter开发的网站.
我正在解析从服务器检索的xml,我想将返回值放入会话变量中.
但是给我这个错误

Fatal error: Uncaught exception ‘Exception’ with message ‘Serialization of ‘SimpleXMLElement’ is not allowed

我的vps上的PHP版本是:
PHP版本5.3.10-1ubuntu3.4

这是我的代码

$xml = new SimpleXMLElement(curl_exec($ch2));
$error2=curl_getinfo( $ch2,CURLINFO_HTTP_CODE );
curl_close($ch2);
foreach ($xml->DATA as $entry){
    $code_travco = $entry->attributes()->COUNTRY_CODE;
    $name_en =  $entry->COUNTRY_NAME;
    $newdata = array(
        'code'  => $code_travco,'name_en'     =>  $name_en
    );
    $this->session->set_userdata($code_travco.'_nation_en',$newdata);      
 }
可能会尝试在添加之前将其更改为字符串,例如:
foreach ($xml->DATA as $entry){
    $code_travco = (string) $entry->attributes()->COUNTRY_CODE;
    $name_en =  (string) $entry->COUNTRY_NAME;
    $newdata = array(
        'code'  => $code_travco,$newdata);      
 }

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念