如何使用java ROME API在RSS Feed中创建带有image元素的条目?

我正在尝试使用java ROME API创建RSS源。 我的要求是每个条目都应该包含一个Image,如下所示:

   Sample RSS Build Results http://time.is sample RSS build  Ist Feed http://mysampleurl1.com The build was successful! Mon, 08 Aug 2016 10:28:32 GMT http://myimageurl1.com 2016-08-08T10:28:32Z   IInd Feed http://mysampleurl2.com The build was successful! Mon, 08 Aug 2016 10:28:44 GMT 2016-08-08T10:28:44Z   

我是java ROME api的新手。 它提供了package :: com.rometools.rome.feed.synd.SyndImageImpl来设置/获取完整Feed中的图像项,但不在单个条目中。 对于RSS feed中的条目,它具有package :: com.rometools.rome.feed.synd.SyndEntryImpl但它不提供任何设置或获取图像的function。

请帮我解决这个问题。 提前致谢。

RSS规范没有为条目指定图像元素,但您可以使用Image命名空间对其进行扩展。

简短的解决方案可能是这样的:

 SyndEntry entry = new SyndEntryImpl(); .. Element image = new Element("image", Namespace.getNamespace("image", "http://web.resource.org/rss/1.0/modules/image/")); image.addContent("http://localhost/feed/item1_image"); entry.getForeignMarkup().add(image); 

这将导致有效的xml:

    title http://localhost/feed description  entry title 1 http://localhost/feed/item1 http://localhost/feed/item1_image http://localhost/feed/item1    

更强大的方法是创建一个自定义模块,就像他们在这里和这里完成的一样。