XML : How to parse list of XML tags in SimpleXMLParser Android

I am using Retrofit and it's build in SimpleConverterXmlFactory to parse XML data, but I don't know how to parse following XML :

      <Point>        <Name>hello</Name>        <Address>adrs</Address>        <Town>NY</Town>        <County>USA</County>        <Local>           <Name>Service 1</Name>        </Local>        <Local>           <Name>Service 2</Name>        </Local>        <Local>           <Name>Service 3</Name>        </Local>        <Local>           <Name>Service 3</Name>        </Local>        <Local>           <Name>Service 4</Name>        </Local>        <Local>           <Name>Service 5</Name>        </Local>        <Local>           <Name>Service 6</Name>        </Local>     </Point>    

My POJO look like this :

      @Root(name = "Point")      public class Point implements Serializable {        @Element(name = "Name", required = false)      private String name;      @Element(name = "Address", required = false)      private String address1;      @Element(name = "Town", required = false)      private String town;      @Element(name = "County", required = false)      private String county;      @ElementList(name = "Local", required = false, inline = true)      private List<Local> local;        // getters and setters  }    

Which gives me following error :

      java.lang.RuntimeException: org.simpleframework.xml.core.ElementException: Element 'Local' does not have a match in class ie.example.models.xmlModels.Point at line 2  W/System.err:     at retrofit.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:45)  W/System.err:     at retrofit.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:23)  W/System.err:     at retrofit.OkHttpCall.parseResponse(OkHttpCall.java:148)  W/System.err:     at retrofit.OkHttpCall.access$100(OkHttpCall.java:29)  W/System.err:     at retrofit.OkHttpCall$1.onResponse(OkHttpCall.java:94)  W/System.err:     at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:168)  W/System.err:     at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)  W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)  W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)    

How should I write annotation to handle this case?

No comments:

Post a Comment