Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to state the order of Attributes in XML after using JAXB, either in maven or elsewhere

I'm un-marshalling some XML to a string using JAXB. However the order of attributes is not the same as the original XML when running our build scripts via Maven. This is failing some unit-tests which pass perfectly fine in Eclipse.

Any ideas why this would happen? Lots of similar questions here but hard to find a solid answer. :)

like image 661
Andy B Avatar asked Jan 10 '23 09:01

Andy B


1 Answers

The order in which attributes appear in XML is not significant while the order in which elements occur is. JAXB like most XML technologies does not guarantee the order in which the attributes will appear. Your unit tests will need to account for this.

Note

When using Unmarshaller & Marshaller the output XML is based on the mapping metadata and not the ordering of the input XML. The metadata allows you to specify the ordering of elements but not attributes. You can use JAXB's Binder to marshal into an existing document (DOM).

like image 127
bdoughan Avatar answered Jan 12 '23 22:01

bdoughan