我正在使用ROME在Java中创建一个rss提要,但是对于我一生来说,我可以找到它上的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的方法。我宁愿有某种向SyndFeedImpl()添加guid的方法,也不愿重写整个内容 最佳答案
SyndFeed.setURI设置唯一标识符。根据所创建的提要类型(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>
与atom 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>
关于java - 在ROME rss文件上添加guid,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36430622/