java - How to get following XML structure using JaxB -


i have requirement need generate xml having following structure. data populating database going format target xml. have created few classes , tried marshalling bean not able generate following structure. please help.

<component id ="668020">--root element     <xyz>xyz</xyz>     <pqr>pqr</pqr>     <profile>         <abc>abc</abc>         <bcd>bcd</bcd>       </profile>     <twentyseven>         <item>             <one>1</one>             <two>2</two>         </item>         <item>             <one>1</one>             <two>2</two>         </item>         <item>             <one>1</one>             <two>2</two>         </item>      </twentyseven>     <hundred>     <hundred_one>         <item>             <one>1</one>             <two>2</two>         </item>         <item>             <one>1</one>             <two>2</two>         </item>         <item>             <one>1</one>             <two>2</two>         </item>      </hundred_one>     </hundred>   </component> 

assuming xml structure precise, here sample java class structures need follow inorder work along jaxb: root element class.

@xmlrootelement public class component {     private int id;      private profile profile;      private twentyseven twentyseven;      private hundred hundred;      public hundred gethundred() {         return hundred;     }      @xmlelement     public void sethundred(hundred hundred) {         this.hundred = hundred;     }      public int getid() {         return id;     }      @xmlattribute     public void setid(int id) {         this.id = id;     }      /*      * same way add @xmlelement annotation      * setter methods of profile , twentyseven.      */  } 

other sample classes shown below:

public class hundred {     private list<item> items;      public list<item> getitems() {         return items;     }      @xmlelement     public void setitems(list<item> items) {         this.items = items;     } }  public class twentyseven {     private list<item> items;      public list<item> getitems() {         return items;     }      @xmlelement     public void setitems(list<item> items) {         this.items = items;     } }  public class item {     //private <object of type one>     //private <object of type two>      /*      * write getter setter methods , add annotations      * accordingly shown in other sample methods.      */ }  public class profile {     private abc item;      public abc getitem() {         return item;     }      @xmlelement     public void setitem(abc item) {         this.item = item;     }      //bcd goes in same way }  public class abc {     private string param1;      private string param2;      public string getparam1() {         return param1;     }      @xmlelement     public void setparam1(string param1) {         this.param1 = param1;     }      public string getparam2() {         return param2;     }      @xmlelement     public void setparam2(string param2) {         this.param2 = param2;     } } 

i hope should going.

note: classes , methods written in example samples. need modify them according needs.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -