I'm new to this Simple XML serializer and i want to parse the IGN news feed. The problem is that i get the following error:
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
The xml look something like this:
<?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&_render=rss&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…</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 -->
So the parser says that the problem is in the "description" tag that is in the "channel" tag. And i really don't know what I'm doing wrong. Here is my Channel class:
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;
}
}
And this is the method in that I'm executing the deserialization:
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();
}
}
Now to answer my own question. I was playing a little bit and the problem is like Nathan Villaescusa suggested in ignoring the RSS tag. Look like you have to make a class (In this case the RSS class, and it has only one Element called Channel) that has to be the root element of the xml file. I didn't find a solution where i can ignore that element and jump straight to the channel tag. Thanks for your help :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With