如何直接从数据库保存为XML文件


How to save as an XML file directly from the database

目前,我已经将RSS/XML提要写入了数据库,但是我想让这些提要可以公开访问。

例如,对于模块A,我希望你可以去feed.php?module=A,它将生成一个以.xml文件结尾的提要,例如:feed.xml.

来自数据库的示例XML代码:

[?xml version="1.0" encoding="UTF-8"?]
[rss version="2.0"]
[channel]
[title]Module news for module A: D&D[/title]
[description]Desc for module here[/description]
[language]en[/language]
[item]
[title]test article[/title]
[pubDate]Tue, 20 Sep 2011 16:14:20[/pubDate]
[description]A test article would go here.[/description]
[link]http://www.google.com[/link]
[author]esujdt[/author]
[guid]http://www.google.com[/guid]
[/item]
[/channel]
[/rss]

只需发出header()来指定内容处置,它允许您提供文件名:

header('Content-disposition: attachment; filename=feed.xml');
header('Content-type: text/xml');
header('Content-length: ' . strlen($xml));
echo $xml;