How can I do @XmlAttribute in a special order using JAXB?

I have an XML file that needs 3 attributes in an element. How can I arrange the attributes of the street, zip code and city as I wanted?

<address street="Big Street" zip="2012" city="Austin">
</address>
@XmlType(name="Street)
@XmlRootElement(name = "Street")
public class Street {

@XmlAttribute
private String name;

@XmlAttribute
private String type;

    ... set and get method
}
+5
source share
2 answers

You can use @XmlAccessorOrder (has predefined values) or @XmlType (works only for properties) to manage the order.

Samples

Edit:

The JAXB specification does not provide anything for a custom order, but you can do it if your JAXB provider provides you with some features.

A link has been found that talks about ordering using EclipseLink JAXB.

+5
source

, . ( ), :

// The inverse order of name & value seems to make them render in XML in name/value order
@XmlAttribute
protected String value;
@XmlAttribute
protected String name;

XML, :

<attribute name="nameValue" value="valueValue"/>
+8

All Articles