<?php
function list_news($id){
          global $db;
          global $newsinfo;
          $sql="SELECT * FROM {$this->tablename}";
          if($id){
          
          $sql.=" WHERE news_news_id=".$id;
          
          }
          $re=$db->query($sql);
          while($r=$db->fetch_array($re)){
           
           $newsinfo[]=array(
             'news_news_id'    =>$r['news_news_id'],
           
              'news_news_name'      =>$r['news_news_name'],
              'news_category_id'     =>$r['news_category_id'],
              'news_tag_name'      =>$r['news_tag_name'],
              'news_content_info'     =>$r['news_content_info'],
              'news_news_author'     =>$r['news_news_author'],
              'news_is_adit'      =>$r['news_is_adit'],
              'news_is_cancle'     =>$r['news_is_cancle'],
              'news_pub_time'     =>$r['news_pub_time'],
              'news_is_recommand'     =>$r['news_is_recommand'],
              'news_is_hot'      =>$r['news_is_hot'],
              'news_is_settop'      =>$r['news_is_settop'],
              'news_keyword_info'      =>$r['news_keyword_info'],
              'news_title_color'      =>$r['news_title_color'],
              'news_introduction_info'     =>$r['news_introduction_info'],
              'news_hit_count'     =>$r['news_hit_count'],
              'news_xml_path'      =>$r['news_xml_path'],
              'news_source_info'      =>$r['news_source_info']
              
              
           );
          }
         }function arraytoxml($iarr){
    if (is_array($iarr)) {
     foreach ($iarr as $key =>$v) {
      $xmlstr .='<'.$key.'>'.$v.'</'.$key.'>'."\n";
      
     }
    }else{
     return '';
    }
    return $xmlstr;
}
 $news->tablename=$tab['news_news_info'];
 $news->list_news();
 $xml2[]="<?xml version=\"1.0\" encoding=\"utf-8\"?>"."\n";
 $xml2[]="<?xml-stylesheet type=\"text/xsl\" href=\"list_total.xsl\"?>"."\n";
 $xml2[]="<root>";
 foreach($newsinfo as $a=>$b){
  $xml2[]="<item>";
  
  $xml2[]=$news->arraytoxml($b);
  
  $xml2[]="</item>";
  
 }
 
 $xml2[]="</root>";
 $f=fopen("/listnewsxml/list_total.xml","w");
 fwrite($f,join("",$xml2));
 fclose($f);
 unset($newsinfo);
?> 

解决方案 »

  1.   

    超级多,呵呵,差不多有这几个,还有几个的,那些不好用,就不说了,大多数都是用前几个,没必要全部都用,有一些是扩展来的:
    1、DOM
    2、SimpleXML
    3、LibXML
    4、XML Parser
    5、XML Reader
    6、XML Writer
    7、XSL
    8、XSLT
    9、SDO
    10、SDO DAS XML
    11、qtdom
      

  2.   

    光文件写操作就有N种,
    再加上php提供的核心xml操作库,
    以及网友自己写的类.太多了,
    不过建议从手册入手.个人比较喜欢domxml!
      

  3.   

    对,我也比较喜欢domxml,不过用正则也是可以解析,就是慢一些.