I need to generate xml using jaxb as below :
<item>
<key1 id="default">value1</key1>
<key2 id="default">value2</key2>
<key3 id="default">value3</key3>
</item>
how to do this using @XmlPath in jaxb?
i have used below one. But i have multiple keys around 50. how to acheive this?
@XmlPath("key1/@id")
private String attrValue = "default";
@XmlPathis an extension in the EclipseLink MOXy implementation of JAXB (JSR-222). You will need to use the equivalent in MOXy’s mapping file to get the desired behaviour.oxm.xml
What you are looking for is the ability to apply multiple writeable mappings for a field/property. This can’t currently be done via annotations, but can be done using MOXy’s external mapping document.
Item
jaxb.properties
In order to specify MOXy as your JAXB provider you need to add a file called
jaxb.propertiesin the same package as your domain model with the following entry (see: http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html)Demo
The demo code below demonstrates how to bootstrap using MOXy’s external mapping document.
input.xml/Output