I want to create xml from my object, but instead of xml nodes I'd like to create attribute i.e.
@XmlRootElement
class MyObject{
private String name;
private String age;
...getters/setters...
}
And I want my object to create this xml :
<MyObject name="something">
<age></age>
</MyObject>
How can I do this?
You can use the @XmlAttribute annotation to map to an XML attribute.
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
class MyObject{
@XmlAttribute // Maps to an XML attribute
private String name;
private String age; // Maps to an XML element
...getters/setters...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With