1

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 ?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
J.BizMai
  • 2,621
  • 3
  • 25
  • 49

2 Answers2

5

I found my solution thanks to @kjhughes. I had to switch from XSD 1.0 processor to XSD 1.1 processor.

In PHPstorm : Settings panel > Languages & Frameworks > Default XML Shemas

enter image description here

Notice : after to 'Apply' changes, you must restart PHPStorm.

J.BizMai
  • 2,621
  • 3
  • 25
  • 49
0

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).

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • In my case, the XSD processor is linked to PHPStorm ? – J.BizMai Mar 09 '18 at 14:56
  • Yes. You can try [configuring PHPStorm for XSD 1.1](https://www.jetbrains.com/help/phpstorm/validating-web-content-files.html), but you may find that such configuration only allows you to validate a XSD 1.1 document itself against the XSD 1.1 schema of schemas; it may not actually invoke a XSD 1.1 processor to enable XSD 1.1 validation against instance XML documents. Perhaps a PHPStorm user or JetBrains employee could say for sure. – kjhughes Mar 09 '18 at 15:07