【发布时间】:2012-01-13 03:31:23
【问题描述】:
在我的 node.js 服务器上,我需要将一些 JSON 转换为 RSS 提要。做这个的最好方式是什么?完成转换后,它需要输出/覆盖一个 RSS 文件。
【问题讨论】:
标签: javascript xml json node.js rss
在我的 node.js 服务器上,我需要将一些 JSON 转换为 RSS 提要。做这个的最好方式是什么?完成转换后,它需要输出/覆盖一个 RSS 文件。
【问题讨论】:
标签: javascript xml json node.js rss
考虑使用https://github.com/dylang/node-rss
示例:
test.json:
{
"title": "foo",
"description": "bar",
"author": "hello"
}
test.js:
var fs = require('fs')
, RSS = require('rss');
fs.readFile('test.json', function(err, data) {
if (!err) {
feed = new RSS(JSON.parse(data));
fs.writeFile('feed.xml', feed.xml());
}
});
运行node test.js 将生成feed.xml:
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title> <![CDATA[foo]]></title>
<description><![CDATA[bar]]></description>
<link>http://github.com/dylan/node-rss</link>
<generator>NodeJS RSS Module</generator>
<lastBuildDate>Fri, 13 Jan 2012 03:44:22 GMT</lastBuildDate>
</channel>
</rss>
【讨论】: