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

后端 未结 8 1899
囚心锁ツ
囚心锁ツ 2020-12-06 10:01

Our C++ application reads configuration data from XML files that look something like this:


 

        
相关标签:
8条回答
  • 2020-12-06 10:53

    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).

    0 讨论(0)
  • 2020-12-06 10:53

    From what I recall, Expat is a non validating parser and better for it.. so you can probably scrap that XSD idea. Neither is the order-dependent a good idea in many XML approaches (XSD got criticised on element order a heck of a lot back in the day, for example, by pro or anti- sellers of XML Web Services at MSFT).

    Do your custom encoding and simply extend either your logic for more efficient lookup or dig into the parser source. It is trivial to write the tooling around encoding efficient replacement whilst shielding the software agents and users from it.. you want do to this so it is easily migrated while preserving backward compatibility and reversibility. Also, go for fixed-size constraints/attribute-name-translation.

    [ Consider yourself lucky with Expat :) and its raw speed. Imagine how CLR devs love XML scaling facilities, they routinely send 200MB on the wire in process of 'just querying the database' .. ]

    0 讨论(0)
提交回复
热议问题