2013-02-26 3 views
4

ROM/파서를 사용하여 RSS/Atom 피드를 구문 분석합니다. 이제 문제는 뉴스 피드/엔트리의 이미지 URL을 제공하지 않는다는 것입니다. 문제의 일부는 피드가 일관성이없고 이미지 URL이 일관성이 없기 때문입니다.로마 API를 사용하여 피드에서 이미지 URL을 읽을 수 없습니다.

BBC 뉴스 <media:thumbnail...> 요소

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

내부에 이미지 URL을두고 그러나 뉴스의 일부는 인클로저 요소 안에 넣어 이미지를 공급한다. 그리고 일부 사료에는 사료가 전혀 들어 있지 않습니다.

내 문제는 그렇습니다. 피드에있는 경우 어떻게 가져올 수 있습니까? 지금까지 로마 API는 완벽하게 작동했습니다. 그러나 지금 나는 이것에 붙어있다.

답변

8

피드에서 이미지 URL을 가져 오는 방법을 찾을 수 있습니다. 문제의 일부는 로마가 제네릭을 사용하지 않기 때문입니다. 그래서 <media:thumbnail.. 요소를 올바르게 읽을 수 없었고 따라서 속성으로 오는 이미지의 URL을 잃어 버리고있었습니다.

디버깅 후 나는 정확한 매개 변수화 된 유형을 알아낼 수 있으며, 다음이었다 쉽게 :

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 to understand the architecture of Rome

이 또한 내가 발견 한 것은,

List<SyndEnclosure> encls = entry.getEnclosures(); 
    if(!encls.isEmpty()){ 
    for(SyndEnclosure e : encls){ 
    String imgURL = e.getUrl().toString(); 
    }      
    } 
: <media:thumbnail.. 요소 피드 없으면

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

그래서 제가 enclosure 또한 소자의 검사하고 다음 화상의 URL은 인클로저 내부 요소 아래와 같다