简体   繁体   中英

JAXB - add multiple @XmlElement

I need the following XML structure for my dokument

<elem_one>
<elem_alpha>
<elem_beta>
<elem_gama>
<elem_two>

And in my case, I want the three elements in the middle grouped in a class, so that my java class looks like

@XmlAccessorType(XmlAccessType.NONE)
public class InsertOrUpdatePeriodicPaymentRequestXML {
   @XmlElement(name="elem_one")
   private Long elementOne;

   // what annotation can I use here?
   private Letters letters;

   @XmlElement(name="elem_two")
   private Long elementTwo;
}

// ====================

public Class Letters {       
   @XmlElement(name="elem_alpha")
   private Long elementAlpha;

   @XmlElement(name="elem_beta")
   private Long elementBeta;

   @XmlElement(name="elem_gama")
   private Long elementGama;    
}

Can you please help me with this? With the code above, I would have only two elements in my XML document:

<elem_one>
<elem_two>

If you are using MOXy as you JAXB (JSR-222) provider you can use our @XmlPath extension:

@XmlPath(".")
private Letters letters;

For More Information

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