【问题标题】:Android RSS reader using SimpleXml and Retrofit - media:thumbnail parse issue使用 SimpleXml 和 Retrofit 的 Android RSS 阅读器 - 媒体:缩略图解析问题
【发布时间】:2017-05-03 06:47:52
【问题描述】:

如何使用 simpleXml 解析来自 RSSItem 的 media:thumbnail url 值?

这是我的 RSSItem 类:

 @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;
    }

}

一切正常,但我还需要在这里解析来自 xml(媒体:缩略图)的图像 url:

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

【问题讨论】:

    标签: java android xml-parsing rss simple-framework


    【解决方案1】:

    你需要使用@Attribute注解来获得这个。

    &lt;media:thumbnail ...&gt;中,media是一个命名空间,你只需要使用thumbnail来访问内容。

    例子:

    @Element(name = "thumbnail", required = false)
    private Thumbnail thumbnail;
    
    @Root(name = "thumbnail", strict = false)
    static class Thumbnail {
    
        @Attribute(name = "url")
        private String url;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-23
      • 2018-12-27
      • 1970-01-01
      • 2016-03-07
      • 2012-09-20
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多