We have been using JAXB to generate XML to interface with a third party. This third party is asking that for one section we produce a set of 2 different 0-n XML Elements in a repeating fashion without parent-elements separating them. Here is an example of whats requested:
<education>
<code>ENG24</code>
<percentage>25</percentage>
<code>ENG25</code>
<percentage>20</percentage>
<code>SPA50</code>
<percentage>30</percentage>
<code>SPA60</code>
<percentage>25</percentage>
</education>
I cannot figure out a way to represent this type of XML with JAXB Java XML Binding. Is it at all possible to represent the above XML with JAXB Java XML Binding?
I am aware that the XML above is poorly designed but I cannot change the third party's mind to use and tags instead.
If JAXB XML binding is not going to work that I would be very thankful for suggestions of what library/tool to use instead to produce XML and to do the marshal/un-marshaling.
Thanks! Matt
Yes, it is possible. The simplest would be probably to use
@XmlElements/@XmlElementcombo:Alternatively you can also use
@XmlElementRef/@XmlElementRefand have aList<JAXBElement<? extends Serializable>> items. Each item would be then aJAXBElement<? extends Serializable>carrying the value as well as name of the element.But since you seem to have different types (
String/Integer),@XmlElements/@XmlElementshould work as well and is much easier to use.