java - Simple XML - how to get data starting from an inner element? -


i trying create elements xml using simple xml android , not interested in root, nested elements. interested in getting account object below xml.

<response xmlns="http://abc.abcdef.com/rest/xyz">     <request>         <channel>334892326</channel>         <number>486</number>     </request>     <status>         <code>200</code>     </status>     <results>         <account>             <creationtimestamp>2014-01-12t1:31:07z</creationtimestamp>             <category>                 <type>user-1</type>                 <name>user-1</name>             </category>         </account>     <results> </response> 

i have tried following in bean, resulting object containing values null.

@root(strict = false, name = "account") @path("response/results/account") public class account implements serializable {      @element(required = false)     private string creationtimestamp;      @element(required = false)     private category category; } 

at first specified xml isn't well-formed. main issue caused path annotation - "... map attributes , elements associated field or method", doesn't work classes, methods , fields.

so code parses xml structure (simplified version):

import org.simpleframework.xml.element; import org.simpleframework.xml.path; import org.simpleframework.xml.root; import org.simpleframework.xml.core.persister;  import java.io.file;  @root(strict = false) public class account {      @element     @path("results/account")     string creationtimestamp;      @element     @path("results/account")     category category;      public static void main(string[] args)             throws exception     {         account account = new persister().read(account.class, new file("example.xml"));          system.out.println(account.creationtimestamp);         system.out.println(account.category.type);         system.out.println(account.category.name);     } }  @root class category {      @element     string type;      @element     string name; } 

unfortunately @path annotation couldn't extracted class annotation, that's why have write every field.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -