0

I have this snippet of a schema that fails to validate.

<?xml version="1.1" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:group name="colorrgbGroup">
    <xs:all>
        <xs:element name="r" type="xs:unsignedShort" minOccurs="1" maxOccurs="1"/>
        <xs:element name="g" type="xs:unsignedShort" minOccurs="1" maxOccurs="1"/>
        <xs:element name="b" type="xs:unsignedShort" minOccurs="1" maxOccurs="1"/>
        <xs:element name="a" type="xs:unsignedShort" minOccurs="0" maxOccurs="1"/>
    </xs:all>
</xs:group>

<xs:group name="colornameGroup">
    <xs:all>
        <xs:element name="colorName" type="xs:normalizedString" minOccurs="1" maxOccurs="1"/>
        <xs:element name="a" type="xs:unsignedShort" minOccurs="0" maxOccurs="1"/>
    </xs:all>
</xs:group>

<xs:group name="colorpresetGroup">
    <xs:all>
        <xs:element name="preset" type="xs:normalizedString" minOccurs="1" maxOccurs="1"/>
        <xs:element name="a" type="xs:unsignedShort" minOccurs="0" maxOccurs="1"/>
    </xs:all>
</xs:group>

<xs:element name="color">
    <xs:complexType>
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:group ref="colorpresetGroup"/>
            <xs:group ref="colornameGroup"/>
            <xs:group ref="colorrgbGroup"/>
        </xs:choice>
    </xs:complexType>
</xs:element>
</xs:schema>

I am trying to say the element color has one of the three possible groups as a child and can only have one of the options one time. As you can see, all three options have the alpha channel as being optional.

If I change the '<'xs:all'>' tags to '<'xs:sequence'>' tags it validates properly. But for the "colorrgbGroup" we want the user to be able to put RGBA, ABGR, ARGB, BGRA, etc., thus being why we prefer to use '<'xs:all'>' over '<'xs:sequence'>'.

I am using this website to check my validation.

Each of the '<'xs:group'>' options inside my '<'xs:choice'>' gives me the following error.

Error - Line 30, 51: org.xml.sax.SAXParseException; lineNumber: 30; columnNumber: 51 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.

I have dealt with schemas and modified existing schemas previously, but this is my first time actually writing one from scratch. Any help is greatly appreciated!

Thanks! Todd

Todd
  • 90
  • 6

1 Answers1

1

Basically, you can't mix xs:all with xs:choice or xs:sequence. If your content model uses xs:all, then that's all it can use.

The rule name cos-all-limited kind-of sums it up...

It wouldn't be allowed even if there were no common elements across the groups, so it's not simply the ambiguity (of encountering an 'a' as the first child and not knowing which group to use) that's the problem. It's just something you can't do.

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