Search code examples
xmlxsdphpstormxsd-validationxsd-1.1

XSD 1.1 - Invalid content was found starting with with element 'xs:alternative'


In my XSD, I'm trying to use alternative tag. For some reasons, I got this error in my IDE (PHPStorm) :

Invalid content was starting with with element 'xs:alternative' ...

XSD

<xs:complexType name="tableType">
    <xs:sequence>
        <xs:element type="columnType" name="column" maxOccurs="unbounded" minOccurs="0"/>
        <xs:element type="keyType" name="key" maxOccurs="unbounded" minOccurs="0">
            <xs:alternative test="@type='index'" type="keyIndexType"/>
            <xs:alternative test="@type='unique'" type="KeyUniqueType"/>
        </xs:element>
    </xs:sequence>
    <xs:attribute type="xs:string" name="name" use="required"/>
</xs:complexType>

I saw I should not add something more to use the 1.1 xsd version but do I need something to support alternative tag ?


Solution

  • Your XSD processor must support XSD 1.1 in order to use xs:alternative (Conditional Type Assignment). An XSD 1.0 processor will not allow xs:alternative as a child of xs:element and will provide an error message such as the one you received. Therefore, you can conclude that your XSD processor only supports XSD 1.0.

    For a working example of CTA, see How to make type depend on attribute value using Conditional Type Assignment (but, of course, this too requires XSD 1.1).