0

I have a schema file with the following contents. I am getting error

cos-all-limited.1.2: An 'all' model group must appear in a particle with '{'min occurs'}' = '{'max occurs'}' = 1, and that particle must be part of a pair which constitutes the '{'content type'}' of a complex type definition.

How can I resolve this?

<?xml version="1.0"?>`enter code here`
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:group name="custGroup">
  <xs:all>
    <xs:element name="customer" type="xs:string"/>
    <xs:element name="orderdetails" type="xs:string"/>
    <xs:element name="billto" type="xs:string"/>
    <xs:element name="shipto" type="xs:string"/>
  </xs:all>
</xs:group>

<xs:element name="order" type="ordertype"/>

<xs:complexType name="ordertype">
<xs:choice>
  <xs:group ref="custGroup"/>
  <xs:element name="status" type="xs:string"/>
  </xs:choice>
</xs:complexType>

</xs:schema>
Abel
  • 56,041
  • 24
  • 146
  • 247
Ananth
  • 1,065
  • 1
  • 12
  • 20

2 Answers2

1

Do not use all this way, it violates the deterministic principle of XSD's. You can fix this by accepting that you want a fixed order of elements (usually the best thing), or by changing it to a choice with 4..4 sequence and each element as itself (define them globally to get this).

Here's one way to do this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:group name="custGroup">
        <xs:sequence>
            <xs:element name="customer" type="xs:string"/>
            <xs:element name="orderdetails" type="xs:string"/>
            <xs:element name="billto" type="xs:string"/>
            <xs:element name="shipto" type="xs:string"/>
        </xs:sequence>
    </xs:group>

    <xs:element name="order" type="ordertype"/>

    <xs:complexType name="ordertype">
        <xs:choice>
            <xs:element name="status" type="xs:string"/>
            <xs:group ref="custGroup"/>
        </xs:choice>
    </xs:complexType>

</xs:schema>
Abel
  • 56,041
  • 24
  • 146
  • 247
  • using sequence enforces the order, which is not what I want :( – Ananth Sep 09 '15 at 10:34
  • @Ananth, in XSD, the choice among children is either that they are all unordered, or that they order. You can mix order with non-order (you want the first item to be positioned, the rest to be unordered). [This is a limitation with XSD](http://stackoverflow.com/questions/15827278/xsd-validation-error-cos-all-limited-1-2-an-all-model-group-must-appear-in) (not with XML). RelaxNG (another schema method) does not have this limitation – Abel Sep 09 '15 at 11:02
  • @Ananth, so you can choose to have `status` as part of the `xs:all`, or you need to manually create a chain of choices with min/max that ultimately have the same effect as `xs:all`, but is also a lot of work. – Abel Sep 09 '15 at 11:03
  • @Ananth, correction, that wouldn't work either, as you would still violate the same basic principle. If you do that, you will receive _[...] violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles."_ And ambiguity is not allowed, it's called _trying to fool the system_. ;) – Abel Sep 09 '15 at 11:09
  • 1
    @Ananth: `xs:all` isn't nearly as orthogonal in XSD as one would expect. You'll be better off just using `xs:sequence` as Abel suggests. – kjhughes Sep 09 '15 at 11:14
0

You can't "resolve" it without getting the spec changed, which ain't going to happen. You can either change your content model to one that XSD supports, or you can use a different validation technology.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164