Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collections in XML SChema

Tags:

xml

xsd

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.

like image 975
Sean Thoman Avatar asked Dec 29 '22 00:12

Sean Thoman


1 Answers

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>
like image 176
Aliostad Avatar answered Jan 16 '23 08:01

Aliostad