本文介绍了如何使用java ROME API在RSS Feed中创建带有image元素的条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create the RSS Feeds using java ROME API. My requirement is that every entry should contain an Image as given below:

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Sample RSS Build Results</title>
    <link>http://time.is</link>
    <description>sample RSS build</description>
        <item>
          <title>Ist Feed</title>
          <link>http://mysampleurl1.com</link>
          <description>The build was successful!</description>
          <pubDate>Mon, 08 Aug 2016 10:28:32 GMT</pubDate>
          <image>http://myimageurl1.com</image>
          <dc:date>2016-08-08T10:28:32Z</dc:date>
        </item>
        <item>
          <title>IInd Feed</title>
          <link>http://mysampleurl2.com</link>
          <description>The build was successful!</description>
          <pubDate>Mon, 08 Aug 2016 10:28:44 GMT</pubDate>
          <dc:date>2016-08-08T10:28:44Z</dc:date>
        </item>
</channel>

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

I am new to java ROME api. It provides the package :: com.rometools.rome.feed.synd.SyndImageImpl to set/get image item in complete feed but not in individual entries. For an entry in RSS feed it has package :: com.rometools.rome.feed.synd.SyndEntryImpl but it does not provide any function for setting or getting image.

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

Please help me to resolve this issue.Thanks in advance.

推荐答案

没有为条目指定图像元素,但您可以使用。

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

这将产生有效的xml:

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.

这篇关于如何使用java ROME API在RSS Feed中创建带有image元素的条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:54