I have already asked this question. I think i might have asked this question wrong previously. I want an xsd element with same type to appear three times in the xsd. I want to know if it is possible.
I have given below my expected xml output.
<Primary>
<Name>Harold</Name> (guy1 data)
<Mobile>2356</Mobile>
</Primary>
<Primary>
<Name>Finch</Name>(guy2 data)
<Mobile>4567</Mobile>
</Primary>
<Primary>
<Name>John</Name>(guy3 data)
<Mobile>1234</Mobile>
</Primary>
I have created XSD for this intended xml.
<xs:element name="primary" minOccurs="0" maxOccurs="unbounded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="mobile" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Here is the scenario I want. I know the primary tag will appear exactly three times in my xml. I was wondering if I could make the elements also appear three times in the xsd. Maybe something like this
<xs:element name="primary" minOccurs="0" maxOccurs="unbounded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="mobile" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="primary" minOccurs="0" maxOccurs="unbounded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="mobile" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="primary" minOccurs="0" maxOccurs="unbounded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="mobile" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
I apologize in advance if it is a silly question. I am very new to XSD and XML. The reason I need it to appear three times in the xsd is I am creating the xml from Tf xml generator in Visual studio 2012. And I need to map the data one to one in the xsd. If I use the complex type and sequence, it appears only once in the xsd and I can’t relate the data of guy 2 and guy 3 to the tags as it appears only once in the xsd. I am trying to do this as I am trying to avoid coding. If I this can’t be done, I will look into use the script component in visual studio ssis package.
Finally after a month of searching and researching i found the answer today.
How to create a schema for an unordered list of XML nodes, with occurrence constraints
Validating XML with XSDs ... but still allow extensibility
Thanks to these two posts i was able to create an xsd which will make the tags appear thrice in my xsd with the use of xs:choice tag