Collections in XML SChema

Studying the XML schema, I want to be able to collect elements inside another element. It seems simple enough, not quite sure how to do this, though.

This is the diagram:

<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'm trying to create something like this:

 <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, he tells me that I can only have one ProcMapping inside a MappingSection. In particular, this invokes the 2nd ProcMapping element for the MappingSection namespace.

+4
source share
1 answer

You need to install minOccurs and maxOccurs . Since they have a default value of 1, only one item is allowed.

So, I would define:

 <xs:complexType name="ProcedureMappingSection"> <xs:sequence> <xs:element name="ProcMapping" type="ProcedureMapping" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> 
+8
source

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


All Articles