1

Possible Duplicate:
How can I make @XmlAttribute in a special order by using JAXB?

For readability, I need my marshalled xml to look like this:

<tag-name name="name" attr1="value1" attr2="value2"/>

Now, when I marshall it, it comes out like this:

<tag-name attr2="value2" attr1="value1" name="name"/>

Is there anything I can do about this? I saw in this question that you can use @XmlType(propOrder={"c","b", "a"}) or @XmlAccessorOrder(XmlAccessOrder.ALPHABETICAL), but I don't think those work with attributes.

My marshalling code is as follows:

public String writeClass(final Foo objectToBeMarshalled) throws JAXBException{
        // marshal
        final JAXBContext context = JAXBContext.newInstance(Foo.class);
        final Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        final StringWriter writer = new StringWriter();
        marshaller.marshal(objectToBeMarshalled, writer);
        return writer.toString();
    } 
Community
  • 1
  • 1
chama
  • 5,973
  • 14
  • 61
  • 77

0 Answers0