我正在使用ROME在Java中创建一个rss feed,但就我而言,我可以找到它上面的GUID。
public boolean addRss(String msg,String msgLink,Date date){
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndEntry entry;
entry = new SyndEntryImpl();
entry.setTitle(msg);
if(msgLink!=null){
entry.setLink(msgLink);
}
entry.setPublishedDate(date);
entries.add(entry);
feed.setEntries(entries);
return true;
}
此代码适用于创建rss项目。问题是我需要添加一个时间戳作为GUID。所以我试着使用Guid对象
Guid g=new Guid();
g.setValue(date.toString());
g.setPermaLink(false);
但是我无法找到将其添加到我的项目的方法,例如没有entry.setGuid(Guid)
修改
事实证明,Guid()
可以添加到Item()
而不是SyndFeedImpl()
,就像我的情况一样,我无法找到一种方法将项目添加到我的SyndFeedImpl。我宁愿有一些方法来添加一个guid到SyndFeedImpl()而不是重写整个事情
答案 0 :(得分:3)
SyndFeed.setURI设置唯一标识符。根据您正在创建的Feed类型(atom / rss),生成的xml会有所不同,但无论如何标识符都在那里:
SyndEntry entry = new SyndEntryImpl();
entry.setTitle("entry title 1");
entry.setUri("http://localhost/feed/item1GUID");
entry.setLink("http://localhost/feed/item1");
结果为rss 2.0:
<item>
<title>entry title 1</title>
<link>http://localhost/feed/item1</link>
<guid isPermaLink="false">http://localhost/feed/item1GUID</guid>
</item>
与原子1.0相同的条目:
<entry>
<title>entry title 1</title>
<link rel="alternate" href="http://localhost/feed/item1" />
<author>
<name />
</author>
<id>http://localhost/feed/item1GUID</id>
</entry>