xml - XSD: Different maxOccurs for specific substitute -


i have simple xml structure looks follows

... <param>   <name>foo</name>   <type1>      complex content   </type1> </param> <param>   <name>bar</name>   <type2>      complex content   </type2> </param> ... 

the schema use looks this

... <xs:complextype name="par">   <xs:sequence>     <xs:element name="name" type="xs:string"/>     <xs:element ref="typespecific"/>   </xs:sequence> </xs:complextype>  <xs:element name="typespecific" abstract="true"/> <xs:element name="type1" type="t1" substitutiongroup="typespecific"/> <xs:element name="type2" type="t2" substitutiongroup="typespecific"/> ... 

i want extend if use type1 in param, can have 1 such element, if use type2 can have many, this:

... <param>   <name>bar</name>   <type2>      complex content   </type2>   ...   <type2>      other complex content   </type2> </param> 

i want avoid wrapping type2 elements in container because of compatibility issues. first impulse use maxoccurs="unbounded" attribute <xs:element name="type2" type="t2" substitutiongroup="typespecific" maxoccurs="unbounded"/>, not allowed.

is there way enforce restriction xsd using current structure? can in way use <xs:choice> instead of substitution achieve this?

xsd 1.0 doesn't allow type of 1 element depend on content of another.

you can implement such dependencies in xsd 1.1 using assertions.

edit: can't substitution groups: if elements substitutable each other, occurrence constraints both must same. you'll need explicit content model choice in it.


Comments