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

前端 未结 2 1602
北恋
北恋 2021-01-13 12:35

I don\'t understand how I should define my complex type.

Today I have this:


    

        
2条回答
  •  隐瞒了意图╮
    2021-01-13 13:22

    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.

提交回复
热议问题