问题
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 ?
回答1:
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).
回答2:
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
Notice : after to 'Apply' changes, you must restart PHPStorm.
来源:https://stackoverflow.com/questions/49196115/xsd-1-1-invalid-content-was-found-starting-with-with-element-xsalternative