5

このSimpleXMLシリアライザーは初めてで、IGNニュースフィードを解析したいと思います。問題は、次のエラーが発生することです。

Unable to satisfy @org.simpleframework.xml.Element(data=true, name=description, required=true, type=void) on field 'description' private java.lang.String org.android.entities.Channel.description for class org.android.entities.Channel at line 2

xmlは次のようになります。

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.ign.com/~d/styles/itemcontent.css"?><rss xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
   <channel>
      <title>IGN All</title>
      <description>The latest IGN news, reviews and videos about video games, movies, TV, tech and comics</description>
      <link>http://pipes.yahoo.com/pipes/pipe.info?_id=5985e93c1e0bc73949d56890f4462756</link>
      <atom:link rel="next" href="http://pipes.yahoo.com/pipes/pipe.run?_id=5985e93c1e0bc73949d56890f4462756&amp;_render=rss&amp;page=2" />
      <pubDate>Wed, 17 Oct 2012 20:05:24 +0000</pubDate>
      <generator>http://pipes.yahoo.com/pipes/</generator>
      <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.ign.com/ign/all" /><feedburner:info uri="ign/all" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.ign.com%2Fign%2Fall" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.ign.com%2Fign%2Fall" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><item>
         <title>Young Justice: "Before the Dawn" Review</title>
         <link>http://feeds.ign.com/~r/ign/all/~3/-l_luafUGXM/young-justice-before-the-dawn-review</link>
         <description>DC Nation has been pulled for now, but we've seen the one last episode of Young Justice that sneaked through: "Before the Dawn" reviewed!</description>
         <guid isPermaLink="false">507deab69e4e6be8947d4a79</guid>
         <pubDate>Wed, 17 Oct 2012 19:32:42 +0000</pubDate>
         <content:encoded><![CDATA[<p><strong>Full superhero sidekick spoilers follow.</strong>
</p><p>Have you heard the news, folks? <a rel="nofollow" target="_blank" href="http://www.ign.com/articles/2012/10/15/new-young-jusice-green-lantern-episodes-abruptly-pushed-to-2013">Cartoon Network abruptly pulled its DC Nation block of programming</a> -- which includes Young Justice and Green Lantern: The Animated Series -- this past weekend, leaving fans confused (and then angry) by the sudden, unexplained move. But what seems to have been an eleventh-hour decision means that the episodes that were originally scheduled to air on Saturday were still made available on iTunes for legal purchase (probably because someone forgot to pull them too). Which means we have this one last review for you before yet another Young Justice hiatus begins…
</p><p><a rel="nofollow" target="_blank" href="http://www.ign.com/articles/2012/10/17/young-justice-before-the-dawn-review">Continue reading&hellip;</a></p>]]></content:encoded>
         <media:content height="341" type="image/jpeg" url="http://oyster.ignimgs.com/wordpress/stg.ign.com/2012/10/robin_batgirl_young_justice.jpg" width="610" />
      <feedburner:origLink>http://feeds.ign.com/~r/ign/articles/~3/ts68IIyx4XI/young-justice-before-the-dawn-review</feedburner:origLink></item>
...
</channel>
</rss><!-- fe1.yql.bf1.yahoo.com compressed/chunked Wed Oct 17 20:05:23 UTC 2012 -->

したがって、パーサーは、問題は「channel」タグにある「description」タグにあると言います。そして、私は本当に私が間違っていることを知りません。これが私のチャンネルクラスです:

package org.android.entities;

import java.io.Serializable;
import java.util.List;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;


    @Root public class Channel implements Serializable{


    /**
     * 
     */
    private static final long serialVersionUID = -6866019353714061968L;

    public Channel() {
        // TODO Auto-generated constructor stub
    }

    @Element
    private String title;

    @Element
    private String description;

    @Element
    private String link;

    @Element
    private String pubDate;

    @ElementList
    private List<Item> item;

    public String getTitle() {
        return title;
    }

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

    public String getDescription() {
        return description;
    }

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

    public String getLink() {
        return link;
    }

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

    public String getPubDate() {
        return pubDate;
    }

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

    public List<Item> getNews() {
        return item;
    }

    public void setNews(List<Item> news) {
        this.item = news;
    }
}

そして、これは私が逆シリアル化を実行しているという点での方法です:

private void getFromCache() {
        Serializer serializer = new Persister();
        try {
            data = serializer.read(Channel.class, destinationFile, false);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
            e.printStackTrace();
        }
    }
4

1 に答える 1

2

今、私自身の質問に答えます。私は少し遊んでいましたが、問題はNathanVillaescusaがRSSタグを無視することを提案したようなものです。xmlファイルのルート要素である必要があるクラス(この場合はRSSクラスであり、Channelと呼ばれる要素が1つしかない)を作成する必要があるように見えます。その要素を無視してチャンネルタグに直接ジャンプできる解決策は見つかりませんでした。ご協力いただきありがとうございます :)

于 2012-10-23T18:58:37.030 に答える