【问题标题】:How to save as an XML file directly from the database如何直接从数据库保存为 XML 文件
【发布时间】:2011-09-20 15:40:18
【问题描述】:

目前,我已将 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]

任何帮助将不胜感激。

【问题讨论】:

  • 这不是 XML...虽然关闭:P
  • 为什么有方括号?另外,问题是什么?如果 XML 已经在数据库中,您可以简单地将其与 application/xml 标头一起提供给最终用户吗?请说明您究竟需要什么帮助。
  • 哎呀忘了在粘贴之前将它们改回来,它们是方形的,因为它被包含在其他地方的 xml 文件中......长话短说,我不是那个工作的人。它们将在我的提要中倾斜。

标签: php mysql sql xml rss


【解决方案1】:

只需发出 header() 来指定 content-disposition,它可以让您提供文件名:

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

【讨论】:

  • 应该是application/rss+xml
猜你喜欢
  • 1970-01-01
  • 2020-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-23
  • 1970-01-01
  • 2013-10-14
  • 2017-05-29
相关资源
最近更新 更多