我正在使用 rome 1.0为我的 Java 应用程序生成 RSS。
在我的java中:
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType( "rss_2.0" );
feed.setTitle( "My Site" );
feed.setLink( "http://example.com" );
feed.setDescription( "Test Site." );
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndEntry entry = null;
SyndContent description = null;
entry = new SyndEntryImpl();
entry.setTitle( "Entry1" );
entry.setLink( "http://example.com/entry1" );
entry.setPublishedDate( new Date() );
description = new SyndContentImpl();
description.setType("text/html");
description.setValue( "This is the content of entry 1." );
entry.setDescription( description );
entries.add( entry );
feed.setEntries(entries);
Writer writer = new FileWriter("/home/jr/Desktop/stream.xml");
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed,writer);
writer.close();
生成的 RSS:
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>My Site</title>
<link>http://example.com</link>
<description>Test Site.</description>
<item>
<title>Entry1</title>
<link>http://example.com/entry1</link>
<description>This is the content of entry 1.</description>
<pubDate>Fri, 09 Nov 2012 01:28:57 GMT</pubDate>
<guid>http://example.com/entry1</guid>
<dc:date>2012-11-09T01:28:57Z</dc:date>
</item>
</channel>
</rss>
当 RSS 被验证时 here , 它有以下建议:
- 项目不应同时包含 pubDate 和 dc:date
- 缺少原子:与 rel="self"的链接
Rome 图书馆如何做推荐?生成的RSS可以吗?
谢谢。
最佳答案
在您的自定义 SyndFeed 类中,确保您命名的 Date 变量与 SyndFeed 类中的名称不同(即:使用类似“pubDate”的名称代替“publishedDate”。这似乎已经解决了我的问题。
public class CustomSyndFeed extends SyndFeedImpl {
protected Date pubDate;
@Override
public Date getPublishedDate() {
return pubDate;
}
@Override
public void setPublishedDate(final Date pubDate) {
this.pubDate = new Date(pubDate.getTime());
}
}
关于java - 使用 Rome 的有效 RSS 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13300903/