<?php
header
( "content-type:text/html;charset=utf-8" );
//使用SimpleXMLElement 类的构造器构造实例化对象并创建根节点
$xml = new SimpleXMLElement( '<Messages></Messages>' );
//连接数据库
mysql_connect( '127.0.0.1' , 'root' , 'root' );
mysql_select_db( 'test' );
mysql_query( 'set names utf8' );
//查询消息
$rs = mysql_query( "select * from blog" );
$i = 0 ;
while ( $row = mysql_fetch_assoc( $rs )){
$xml -> message [ $i ] = '' ;
$xml -> message [ $i ][ 'id' ] = $row [ 'b_id' ];
$xml -> message [ $i ]-> title = $row [ 'b_title' ];
$xml -> message [ $i ]-> content = $row [ 'b_content' ];
$xml -> message [ $i ]-> time = $row [ 'b_date' ];
$i ++;
} $
xml ->asXML( 'messages.xml' );
echo "生成成功!" ;