Copy CodeThe code is as follows:
Include ' mysql.php ';
$mysql = Mysql::getobject ();
$mysql->query ("select * from post");
$xml = new XMLWriter ();
$xml->openuri (' hello.xml '); or ' Php://output '
$xml->setindentstring (");
$xml->setindent (TRUE);
Start
$xml->startdocument (' 1.0 ', ' UTF-8 ');
//
$xml->startelement (' RSS ');
$xml->writeattribute (' Version ', ' 2.0 ');
//
$xml->startelement (' channel ');
Title
$xml->startelement (' title ');
$xml->text (' title ');
$xml->endelement ();
Link
$xml->startelement (' link ');
$xml->text (' http://jb51.net/post/');
$xml->endelement ();
Description
$xml->startelement (' description ');
$xml->text (");
$xml->endelement ();
Language
$xml->startelement (' language ');
$xml->text (' ZH-CN ');
$xml->endelement ();
Category
$xml->startelement (' category ');
$xml->text (' IT ');
$xml->endelement ();
Copyright
$xml->startelement (' copyright ');
$xml->text (' copyright jb51.net ');
$xml->endelement ();
For item
while ($row = $mysql->fetch ())
{
$xml->startelement (' item ');
Title
$xml->startelement (' title ');
$xml->text ($row [' title ']);
$xml->endelement ();
Link
$xml->startelement (' link ');
$xml->text (' http://jb51.net/post/'. $row [' id ']. HTML ');
$xml->endelement ();
Description
$xml->startelement (' description ');
$xml->text ($row [' text ']);
$xml->endelement ();
PubDate
$xml->startelement (' pubDate ');
$xml->text (Date (' d, D M Y h:i:s T ', $row [' time ']);
$xml->endelement ();
Category tag author need to write.
$xml->endelement (); Item
}
$xml->endelement (); Channel
$xml->endelement (); Rss
$xml->enddocument ();
$xml->flush ();
The previous mysql.php is the encapsulated MySQL database feature, singleton mode, so the object is static method Mysql::getobject ();
The code is simple.
The argument to the OpenUri (") method can be a file, then the XML data is written to this file
or php://output output to a buffer, then flush method output to page
http://www.bkjia.com/PHPjc/324399.html www.bkjia.com true http://www.bkjia.com/PHPjc/324399.html techarticle Copy the code as follows: Include ' mysql.php '; $mysql = Mysql::getobject (); $mysql-query ("select * from post"); $xml = new XMLWriter () ; $xml-openuri (' hello.xml '); or ' PHP://OUTP ...