简体   繁体   中英

Android RSS reader using SimpleXml and Retrofit - media:thumbnail parse issue

How to parse the media:thumbnail url value from an RSSItem using simpleXml?

Here is my RSSItem class:

 @Root(name = "item", strict = false)
public class FeedItem {
    @Element(name = "pubDate")
    private String pubDate;
    @Element(name = "title")
    private String title;
    @Element(name = "link")
    private String link;
    @Element(name = "description")
    private String description;


    public FeedItem() {
    }


    public FeedItem(String description, String link, String title, String pubDate) {
        this.description = description;
        this.link = link;
        this.title = title;
        this.pubDate = pubDate;
    }

    public String getPubDate() {
        return pubDate;
    }

    public void setPubDate(String pubDate) {
        this.pubDate = pubDate;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

}

it all works ok, but I need to parse also the image url from the xml (media:thumbnail) here:

<media:thumbnail url="https://tctechcrunch2011.files.wordpress.com/2016/12/gettyimages-591407481.jpg" />

You need to use @Attribute annotation to get this.

In <media:thumbnail ...> , the media is a namespace and you only need to use thumbnail to access the content.

Example:

@Element(name = "thumbnail", required = false)
private Thumbnail thumbnail;

@Root(name = "thumbnail", strict = false)
static class Thumbnail {

    @Attribute(name = "url")
    private String url;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM