XML doesn't care about the order of attributes, and doesn't guarantee any particular order. The order they appear in is most likely an artifact of whatever data structure is used internally to store them.

There is no point in trying to enforce an order in terms of processing; the parser doesn't care. Neither should any output routines - specifications demanding a particular ordering are misguided, at best.