An XML schema can have multiple options in one complexType?

Is it possible to do something like this in an XML schema?

<xsd:complexType name="ItemsType"> <xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="shirt"/> <xsd:element ref="hat"/> <xsd:element ref="umbrella"/> </xsd:choice> <xsd:choice minOccurs="1" maxOccurs="3"> <xsd:element ref="apple"/> <xsd:element ref="banana"/> <xsd:element ref="strawberry"/> </xsd:choice> </xsd:complexType> 

this is apparently invalid. I would like it to be possible to have 0 or more from the first choice. there may be a shirt element and a hat element, or perhaps no clothes elements at all (since minOccurs = "0"), followed by at least 1 fruit element (I want to make it at least one, since MinOccurs = "1").

Is there any way to do this?

Thanks for any help.

+6
source share
1 answer

<xsd:complexType> expects only one child. Wrap the two options inside one <xsd:sequence> .

Example

 <xsd:complexType name="ItemsType"> <xsd:sequence> <xsd:choice minOccurs="0" maxOccurs="unbounded"> ... clothes ... </xsd:choice> <xsd:choice minOccurs="1" maxOccurs="3"> ... fruits ... </xsd:choice> </xsd:sequence> </xsd:complexType> 
+12
source

Source: https://habr.com/ru/post/892176/


All Articles