After a lot of frustration I have come here for help. I am using org.simpleframework.xml to parse RSS feeds in Android. I get the following error when I try to parse the xml file:
org.simpleframework.xml.core.PersistenceException: Element 'link' is already used with @org.simpleframework.xml.Element(data=false, name=, required=true, type=void) on field 'link'
This is a sample of the xml I am trying to parse:
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xml:base="http://www.somelink.com/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>My Title</title>
<description>Latest breaking news, sport, weather and opinion, from South Africa, Africa and the world.</description>
<link>http://www.somelink.com/</link>
<atom:link rel="self" href="http://www.someotherlink.com" />
</channel>
</rss>
These are the classes and annotations that I use in the code:
@Root(name = "rss")
@Namespace(reference = "http://www.w3.org/2005/Atom", prefix = "atom")
public class NewsFeed
{
@Version(revision = 2.0)
private float version;
@Attribute
private String base;
@Element
private Channel channel;
}
@Root(name = "channel")
public class Channel
{
@Element
private String title;
@Element
private String description;
@Element
private String link;
@Element
@Namespace(reference = "http://www.w3.org/2005/Atom", prefix = "atom")
private Link rssLink;
@ElementList(inline = true)
private List<NewsItem> newsItems;
}
@Root(name = "link")
public class Link
{
@Attribute
private String rel;
@Attribute
private String href;
public String getRel()
{
return rel;
}
public void setRel(String rel)
{
this.rel = rel;
}
public String getHref()
{
return href;
}
public void setHref(String href)
{
this.href = href;
}
}
I created the Link class so that I could use the atom namespace. As you can see from the error, the library doesn't appear to be taking the namespace into account and that's why it's complaining that the link element has already been used. What am I doing wrong? Your help would be greatly appreciated.