Can I enforce the order of XML attributes using a schema? Can I enforce the order of XML attributes using a schema? xml xml

Can I enforce the order of XML attributes using a schema?


According to the xml specification,

the order of attribute specifications in a start-tag or empty-element tag is not significant

You can check it at section 3.1


XML attributes don't have an order, therefore there is no order to enforce.

If you want something ordered, you need XML elements. Or something different from XML. JSON, YAML and bEncode, e.g. have both maps (which are unordered) and sequences (which are ordered).


As others have pointed out, no, you can't rely on attribute ordering.

If I had any process at all involving 2,500 XML files and 1.5 million key/value pairs, I would get that data out of XML and into a more usable form as soon as I possibly could. A database, a binary serialization format, whatever. You're not getting any advantage out of using XML (other than schema validation). I'd update my store every time I got a new XML file, and take parsing 1.5 million XML elements out of the main flow of my process.