PHP头条
热点:

php生成xml文档有关问题


php生成xml文档问题
php生成xml,我在网上搜了有四种方法,但是当我自己做的时候结果不对,过程如下:
想要输出的xml是:
  
  
      
        title1  
        content1  
        2009-10-11  
    
  
      
        title2  
        content2  
        2009-11-11  
    
  
 

比如我使用SimpleXML创建XML文档,代码如下(都是网上的例子):

$data_array = array(  
    array(  
    'title' => 'title1',  
    'content' => 'content1',  
        'pubdate' => '2009-10-11',  
    ),  
    array(  
    'title' => 'title2',  
    'content' => 'content2',  
    'pubdate' => '2009-11-11',  
    )  
);  
  
//  属性数组  
$attribute_array = array(  
    'title' => array(  
    'size' => 1  
    )  
);  
  
$string = <<   
  
  
XML;  
  
$xml = simplexml_load_string($string);  
  
foreach ($data_array as $data) {  
    $item = $xml->addChild('item');  
    if (is_array($data)) {  
        foreach ($data as $key => $row) {  
          $node = $item->addChild($key, $row);  
  
          if (isset($attribute_array[$key]) && is_array($attribute_array[$key]))  
            {  
              foreach ($attribute_array[$key] as $akey => $aval) {  
             //  设置属性值  
                  $node->addAttribute($akey, $aval);  
            }  
          }  
        }  

www.phpzy.comtrue/phprm/13458.htmlTechArticlephp生成xml文档有关问题 php生成xml文档问题 php生成xml,我在网上搜了有四种方法,但是当我自己做的时候结果不对,过程如下: 想要输出的xml是: title1 content1 2009-10-11 title2 content2 2009...

相关文章

相关频道:

PHP之友评论

今天推荐