gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 03:18:35 25 4
gpt4 key购买 nike

我正在尝试使用 java ROME API 创建 RSS 提要。我的要求是每个条目都应包含如下所示的图像:

<?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 来设置/获取完整提要中的图像项,而不是单个条目中的图像项。对于 RSS 提要中的条目,它有 package::com.rometools.rome.feed.synd.SyndEntryImpl 但它不提供任何设置或获取图像的功能。

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

最佳答案

The RSS spec没有为条目指定图像元素,但您可以使用 Image namespace 扩展它.

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

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:

<?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>

更稳健的方法是create a custom module就像他们所做的那样herehere .

关于java - 如何使用 java ROME API 在 RSS Feed 中创建带有图像元素的条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38829416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com