What is the alternative to have xsd:sequence behavior inside a xsd:all?

[亡魂溺海] 提交于 2019-12-01 08:05:15
predi

You can use <xsd:choice minOccurs="0" maxOccurs="unbounded"> instead of your xsd:sequence in order to emulate non-ordered element validation. This circumvents the limitations of xsd:all.

C. M. Sperberg-McQueen

In XSD 1.0, your alternatives are (if you want to keep things simple) as you have identified them:

  • sequence, which requires a particular ordering
  • all, which does not.

If the ordering does not carry meaning (so the sequence document-id, filename, author and the sequence author, document-id, filename carry the same information), then there is no loss of expressive power in fixing the sequence. Or you can use an unbounded choice, as suggested by predi, and place part of the validation logic (checking cardinality) in another layer of the application. The vocabulary designers I think most highly of generally recommend a sequence in this situation.

Two other approaches are worth mentioning:

  • In XSD 1.1, the constraints on maxOccurs in all-groups have been lifted (though not the other constraints on all-groups).
  • Since the language you want is clearly a regular language, you can write a content model for it using nested choices and sequences. This is made a bit tedious by XSD's 'unique particle attribution' constraint, which means you have to avoid anything that might make the content model non-deterministic, but it's doable. A concrete example is shown in the answer to another question.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!