0

I'd like

<node a="2" d="1" c="2"> 

to be converted to

<node a="2" c="2" d="1">

Can you propose some solution with less effort?

Stepan Yakovenko
  • 8,670
  • 28
  • 113
  • 206
  • 1
    Might help to explain why you care about the order of the attributes. Any XML parsing code should accept attributes in any order. – Caleb Oct 03 '12 at 19:23
  • Why?!? There is no order in the attributes of an XML node - nor should the "order" matter in any way.... – marc_s Oct 03 '12 at 19:23
  • The solution depends entirely on the programming language, what library you're using, etc. And as marc_s mentioned, this is for aesthetics and possibly better human-readability only. – John Oct 03 '12 at 19:24
  • Well, I've got java code that load and saves xml data. I've migrated from digester to Jaxb. I want to make sure that everything is ok. – Stepan Yakovenko Oct 04 '12 at 05:17

1 Answers1

2

Use an XML canonicalization library. XML canonical form requires the attributes to be in alphabetical order (so that two documents can be compared for equivalence by comparing them at the byte level).

Michael Kay
  • 156,231
  • 11
  • 92
  • 164