I created a web service in Java using a method that returns a string (general list in XML format). I use this web service from Android and I get this line, but after several attempts, the Android emulator just crashes when trying to deserialize the line. This is an example of the line I get:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <peliculas> <pelicula> <id>18329</id> <poster>http://cache-cmx.netmx.mx/image/muestras/5368.rrr.jpg</poster> <titulo>007 Operaci&oacute;n Skyfall</titulo> </pelicula> ... </peliculas>
This is the class in the web service:
@XmlRootElement public class Peliculas{ @XmlElement(name="pelicula") protected List<Pelicula> peliculas; public Peliculas(){ peliculas = new ArrayList<Pelicula>();} public Peliculas(List<Pelicula> pe){ peliculas = pe; } public List<Pelicula> getList(){ return peliculas; } public void add(Pelicula pelicula) { peliculas.add(pelicula); } }
________ EDIT ______________
It looks like you cannot use JAXB with Android, and this requires more / less libraries. so I tried Simple XML. This is the method:
public Peliculas unmarshal(String xml) throws Exception{ Peliculas peliculas = new Peliculas(); Serializer serializer = new Persister(); StringBuffer xmlStr = new StringBuffer( xml ); peliculas = serializer.read(Peliculas.class, ( new StringReader( xmlStr.toString() ) ) ); return peliculas; }
BUT I get this exception, it looks like it cannot save data in the object:
11-12 20:30:10.898: I/Error(1058): Element 'Pelicula' does not have a match in class app.cinemexservice.Pelicula at line 3
Pundia
source share