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


i trying create rss feeds using java rome api. requirement every entry should contain image 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 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 successful!</description>           <pubdate>mon, 08 aug 2016 10:28:44 gmt</pubdate>           <dc:date>2016-08-08t10:28:44z</dc:date>         </item> </channel> 

i new java rome api. provides package :: com.rometools.rome.feed.synd.syndimageimpl set/get image item in complete feed not in individual entries. entry in rss feed has package :: com.rometools.rome.feed.synd.syndentryimpl not provide function setting or getting image.

please me resolve issue. in advance.

the rss spec doesn't specify image elements entries, can extend image namespace.

short solution 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 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 create custom module they've done here , here.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -