How to create entries with image element in the RSS Feed using the java ROME API?

橙三吉。 提交于 2019-12-03 17:23:58

The RSS spec doesn't specify image elements for entries, but you can extend it with Image namespace.

Short solution could be like this:

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);

This will result in valid xml:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>title</title>
    <link>http://localhost/feed</link>
    <description>description</description>
    <item>
      <title>entry title 1</title>
      <link>http://localhost/feed/item1</link>
      <image:image xmlns:image="http://web.resource.org/rss/1.0/modules/image/">http://localhost/feed/item1_image</image:image>
      <guid isPermaLink="false">http://localhost/feed/item1</guid>
    </item>
  </channel>
</rss>

More robust way is to create a custom module like they've done here and here.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!