Failed to read image URL from feed using Rome API

I use the ROME parser to parse my RSS / Atom feeds. Now the problem is that it does not give the URL of the image in the news / post feed. Part of the problem is also related to the fact that the channels are incompatible and they are incompatible with the image URLs.

BBC news puts the URL of the image inside the <media:thumbnail...> element

 <item> <title>Dementia in care homes 'more common'</title> <description>Eight out of 10 residents in care homes are now thought to have dementia or severe memory problems, new data shows.</description> <link>http://www.bbc.co.uk/news/health-21579394#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link> <guid isPermaLink="false">http://www.bbc.co.uk/news/health-21579394</guid> <pubDate>Tue, 26 Feb 2013 00:28:31 GMT</pubDate> <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/66064000/jpg/_66064884_c0016428-geriatric_care-spl.jpg"/> <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/66064000/jpg/_66064885_c0016428-geriatric_care-spl.jpg"/> </item> 

But some news feeds place images inside the attachment element. And some of them do not have them at all.

So my problem; how can i get them if they are present in the feed. So far, the Rome API has worked fine for me; but now I'm stuck with that.

+4
source share
1 answer

I could figure out how to get the image url from the feed. Part of the problem is that Rome does not use Generics; therefore, he was unable to read the <media:thumbnail.. element correctly and, therefore, lost the URL of the image that appears as an attribute.

After debugging, I was able to find the exact parameterized type, and then it was easy :)

  List<Element> foreignMarkups = (List<Element>) entry.getForeignMarkup(); for (Element foreignMarkup : foreignMarkups) { String imgURL = foreignMarkup.getAttribute("url").getValue(); //read width and height } 

This blog helped me understand the architecture of Rome.

And what I found for some news feeds; The URL of the image inside the body element as shown below:

<enclosure url="http://www.wired.com/reviews/wp-content/uploads/2013/02/lights_remote_1-200x100.jpg" type="image/jpeg" length="48000"/>

So I also check the enclosure element if the <media:thumbnail.. element is missing from the feed:

  List<SyndEnclosure> encls = entry.getEnclosures(); if(!encls.isEmpty()){ for(SyndEnclosure e : encls){ String imgURL = e.getUrl().toString(); } } 
+8
source

All Articles