问题
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.
回答1:
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.)
来源:https://stackoverflow.com/questions/26823002/java-jaxb-xml-pojo-classes