Learning XML Schema, I want to be able to have collections of elements inside another element. Seems simple enough, not quite sure how to do it though.
This is the schema:
<xs:attributeGroup name="ProcedureMappingFragment">
<xs:attribute name="ParameterName" type="xs:string" />
<xs:attribute name="TypeName" type="xs:string" />
<xs:attribute name="PropertyName" type="xs:string" />
<xs:complexType name="ProcedureMappingSection">
<xs:sequence>
<xs:element name="ProcMapping" type="ProcedureMapping" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ProcedureMapping">
<xs:attributeGroup id="two" ref="ProcedureMappingFragment" />
<xs:attribute name="ProcedureName" type="xs:string" />
</xs:complexType>
And I am trying to produce something like such:
<MappingSection xmlns="http://tempuri.org/ServiceMapping.xsd">
<ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
<ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
<ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
<ProcMapping ParameterName="ParameterName1" TypeName="TypeName1" PropertyName="PropertyName1" ProcedureName="ProcedureName1" />
</MappingSection>
However it is telling me that I can only have one ProcMapping inside MappingSection. Specifically it is calling the 2nd ProcMapping element invalid for namespace MappingSection.
You need to set the minOccurs
and maxOccurs
. Since they have a default value of 1, only one element is allowed.
So I would define:
<xs:complexType name="ProcedureMappingSection">
<xs:sequence>
<xs:element name="ProcMapping" type="ProcedureMapping" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With