In one of my applications I'm using thegamesdb.net's APIs to download the cover images of some games. To get informations from XML files I'm trying to implement Simple XML library to deserialize.
This is my example query result (name=Splatterhouse,platform=TurboGrafx 16):
<?xml version="1.0" encoding="UTF-8" ?>
<Data>
<Game>
<id>3776</id>
<GameTitle>Splatterhouse</GameTitle>
<ReleaseDate>01/01/1990</ReleaseDate>
<Platform>TurboGrafx 16</Platform>
</Game>
</Data>
And this is how I implemented my classes in java:
@Root
public class Data{
@ElementList(inline=true)
private List<Game> list; //This is correct, it's only in the example that I've only one result.
public List<Game> getGames(){
return list;
}
}
@Root
public class Game{
@Element
private int id;
@Element
private String GameTitle;
@Element(required=false)
private String ReleaseDate;
@Element(required=false)
private String Platform;
public String getTitle(){
return GameTitle;
}
public int getId(){
return id;
}
}
To read from the xml file, I call the serializer:
String xml = getXmlFromUrl(URL);
Serializer serializer = new Persister();
Data data = serializer.read(Data.class, xml);
What's wrong?
UPDATE: It came out that the tutorials on Simple Site are a bit incomplete since they don't set properly annotations, these annotations solved all my issues, plus all the warnings are "normal", it's simple stating that jaxp doesn't exist on android and is going to use other tools (XmlPullParser?).
This is my proper code:
@Root(name = "Data")
public class Data {
@ElementList(inline = true, required = false)
private List<Game> list = new ArrayList<Game>();
public List<Game> getGames() {
return list;
}
}
@Root(name = "Game", strict = false)
public class Game {
@Element(name = "id")
private int id;
@Element(name = "GameTitle")
private String GameTitle;
public String getTitle() {
return GameTitle;
}
public int getId() {
return id;
}
}