java - Correct way to parse XML using Simple Framework -
i'm using simple framework deserialize xml on android app .
the issue on portion of xml because can objects of other portions of .
here part of xml struggle :
<webtv name="channelname" date="2014-10-31"> <config> <pathvideo extension="mp4">http://vodflash.channelname.com/tv_conn/1/country/</pathvideo> <pathbigimage extension="jpg">http://vodflash.channelname.com/tv_conn/1/country/pic/320x180/</pathbigimage> <pathimage extension="jpg">http://vodflash.channelname.com/tv_conn/1/country/pic/160x90/</pathimage> <pays>gb;ie</pays> </config>
here xmlmapper class :
@root(name="webtv", strict = false) public class xmlmodelmapper { public configobject getconfigobjects() { homecoming configobject; } @element(name="config") public configobject configobject = new configobject(); @elementlist(name = "itemlist") private list<videos> itemlist = new arraylist<videos>(); public list<videos> getitemlist() { homecoming itemlist; } @elementlist(name = "chainelist") private list<chaine> chainelist = new arraylist<chaine>(); public list<chaine> getchainelist() { homecoming chainelist; } }
if alter mapper class :
@root(name="webtv", strict = false) public class xmlmodelmapper { public list<configobject> getconfigobjects() { homecoming configobject; } //change here using list not object @elementlist(name="config") public list<configobject> configobjects = new arraylist<configobject>(); @elementlist(name = "itemlist") private list<videos> itemlist = new arraylist<videos>(); public list<videos> getitemlist() { homecoming itemlist; } @elementlist(name = "chainelist") private list<chaine> chainelist = new arraylist<chaine>(); public list<chaine> getchainelist() { homecoming chainelist; } }
and log size of list 4 right , how each object in distinct way including extension (attribute)
please help me solving issue .
thanks
@elementlist(name="config") public list<configobject> configobjects = new arraylist<configobject>();
this wont match xml listed above. while @element
-based solution (example 1) create proper config
-tag, list adds "list-tag"; here's example:
<config> <!-- list's tag, wrapping elements --> <config> <!-- actual element's tag --> <pathvideo extension="mp4">http://video.com</pathvideo> <pathbigimage extension="jpg">http://bigimg.com</pathbigimage> <pathimage extension="jpg">http://image.com</pathimage> <pays>gb;ie</pays> </config> <!-- more <config>...</config> --> </config>
the solution: utilize athe inline list - don't have "list-tag".
@elementlist(name = "config", inline = true, entry = "config") public list<configobject> configobjects = new arraylist<>();
for sake of completeness, here classes used testing:
class chaine { /* empty - plenty testing */ } class videos { /* empty - plenty testing */ } @root public class configobject { @element(name = "pathvideo") private pathconfig video; @element(name = "pathbigimage") private pathconfig bigimage; @element(name = "pathimage") private pathconfig image; @element(name = "pays") private string pays; // ... } @root public class pathconfig { @attribute(name = "extension") private string extension; @text private string path; // ... }
java xml xml-parsing simple-framework
No comments:
Post a Comment