简体   繁体   中英

Java JAXB xml pojo classes

How can I create the POJO classes with JAXB with such a xml structure :

<principale>
   <procedure>
      <procedure>
         <param1>value1</param1>
         <param2>value2</param2>
      </procedure>
      <procedure>
         <param1>value3</param1>
         <param2>value4</param2>
      </procedure>
   </procedure>
</principale>

As you can see the first procedure tag is not the root one and is the same than the second procedure tag.

If the outer procedure element is not repeatable, try it with @XmlElementWrapper :

@XmlRootElement(name="principale")
public class Principale {
    @XmlElementWrapper(name="procedure")
    @XmlElement(name="procedure")
    public List<Params> procedures = new LinkedList<Params>();
}
public class Params {
   @XmlElement(name="param")
   public List<String> params = new LinkedList<String>();
}

(Untested.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM