2011-09-20 65 views
0

目前,我已將RSS/XML供稿寫入數據庫,但我希望將這些供稿公開訪問。如何直接從數據庫中保存爲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] 

任何幫助將非常感激。

+0

這不是XML ...關閉雖然:P –

+0

它爲什麼方括號?另外,問題是什麼?如果XML已經存在於數據庫中,那麼您可以簡單地將它與application/xml頭一起提供給最終用戶?請澄清你到底需要什麼幫助。 – Gordon

+0

請參閱:http://dev.mysql.com/doc/refman/5.1/en/xml-functions.html – Johan

回答

2

只是發出一個頭()來指定內容處置,它可以讓你提供一個文件名:

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

這應該是'application/rss + xml' – Gordon

相關問題