How can I generate the following XML using JAXB?
<sport type="" gender="">
sport description
</sport>
Annotate type and gender properties with @XmlAttribute
and the description property with @XmlValue
:
package org.example.sport;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Sport {
@XmlAttribute
protected String type;
@XmlAttribute
protected String gender;
@XmlValue;
protected String description;
}
For More Information