xsd - XML Schema for collection of components of any of defined type -
i have defined components of types inputtexttype
, inputemailtype
(their definitions not important here). need have components
collection of number inputtext and/or inputemail, in order (example: text, email, text, text). i've tried:
<xs:complextype name="componentstype"> <xs:choice> <xs:element name="inputtext" type="inputtexttype" maxoccurs="unbounded" minoccurs="0"/> <xs:element name="inputemail" type="inputemailtype" maxoccurs="unbounded" minoccurs="0"/> </xs:choice> </xs:complextype>
but when validating xml
<components> <inputtext> <label>label 1</label> <name>as</name> </inputtext> <inputtext> <label>label 2</label> <name>ghyyy6</name> </inputtext> <inputemail> <label>drg</label> <name>rgtght</name> </inputemail> </components>
i have error cvc-complex-type.2.4.a: invalid content found starting element 'inputemail'. 1 of '{inputtext}' expected.
. xml correct (i need it). how should fix xsd?
for xml above changed xsd
<xs:complextype name="componentstype"> <xs:choice> <xs:element name="inputtext" type="inputtexttype" maxoccurs="unbounded" minoccurs="0"/> <xs:element name="inputemail" type="inputemailtype" maxoccurs="unbounded" minoccurs="0"/> </xs:choice> </xs:complextype>
and worked i'm not able define text, email, text, text first texts , emails.
move occurrence constraints xs:choice
:
<xs:choice minoccurs="0" maxoccurs="unbounded"> <xs:element name="inputtext" type="inputtexttype"/> <xs:element name="inputemail" type="inputemailtype"/> </xs:choice>
Comments
Post a Comment