Variable number of occurrences, groups and identifiers

Here are two transformation examples that use variable number of occurrences, groups, and identifiers. Groups are containers used to manage a group of records and other groups, often with a variable number of occurrences. You can control the number of occurrences of a record. You can use an identifier to identify a record.

Example 13 A

This example shows how a field and record-separated flat file with identifiers is transformed to XML.

Flat File Definition:

<BankRepository>
	<Files>
      <File>
         <ID>SampleThirteenA</ID>
			<Messages>
				<Message>
					<IgnorePrecedingFieldSeparator>1</IgnorePrecedingFieldSeparator>
					<DefaultEmptyFieldValue><Numeric>0</Numeric><Alpha></Alpha></DefaultEmptyFieldValue>
					<DefaultAlignment><Numeric>RIGHT</Numeric><Alpha>LEFT</Alpha></DefaultAlignment>
					<DefaultPadding><Numeric>0</Numeric><Alpha> </Alpha></DefaultPadding>
					<DefaultTrim><Numeric>1</Numeric><Alpha>0</Alpha></DefaultTrim>
					<Name>Purchases</Name>
					<TagName>PurchasedItems</TagName>										
					<EscapeChar/>
					<RecordSeparator>\n</RecordSeparator>
					<FieldSeparator>:</FieldSeparator>
               <Records>
                  <Group>
                     <Name>Purchase</Name>
                     <TagName>Purchase</TagName>
                     <MinOccur>0</MinOccur>
                     <MaxOccur>U</MaxOccur>
                     <Records>
                        <Record>
                           <Name>CustomerDetails</Name>
                           <TagName>CustomerDetails</TagName>
                           <MinOccur>1</MinOccur>
                           <MaxOccur>1</MaxOccur>
                           <Fields>
                              <Field>
                                 <Name>ID</Name>
                                 <TagName>Identifier</TagName>
                                 <DataType>Alpha</DataType>
                                 <PaddingChar/>
                                 <DecimalLength/>
                                 <Alignment>LEFT</Alignment>
                                 <StartPos>0</StartPos>
                                 <Length>0</Length>
                                 <DefaultValue>CUSTOMER</DefaultValue>
                                 <Identifier>1</Identifier>
                              </Field>
                              <Field>
                                 <Name>Name</Name>
                                 <TagName>Name</TagName>
                                 <DataType>Alpha</DataType>
                                 <PaddingChar/>
                                 <DecimalLength/>
                                 <Alignment>LEFT</Alignment>
                                 <StartPos>0</StartPos>
                                 <Length>0</Length>
                                 <DefaultValue></DefaultValue>
                                 <Identifier>0</Identifier>
                              </Field>
                              <Field>
                                 <Name>Number</Name>
                                 <TagName>Number</TagName>
                                 <DataType>Alpha</DataType>
                                 <PaddingChar/>
                                 <DecimalLength/>
                                 <Alignment>LEFT</Alignment>
                                 <StartPos>0</StartPos>
                                 <Length>0</Length>
                                 <DefaultValue></DefaultValue>
                                 <Identifier>0</Identifier>
                              </Field>
                           </Fields>
                        </Record>
                        <Group>
                           <Name>Payment</Name>
                           <TagName>Payment</TagName>
                           <MinOccur>1</MinOccur>
                           <MaxOccur>1</MaxOccur>
                           <Records>
                              <Record>
                                 <Name>PaymentDetails</Name>
                                 <TagName>PaymentDetails</TagName>
                                 <MinOccur>0</MinOccur>
                                 <MaxOccur>1</MaxOccur>
                                 <Fields>
                                    <Field>
                                       <Name>ID</Name>
                                       <TagName>Identifier</TagName>
                                       <DataType>Alpha</DataType>
                                       <PaddingChar/>
                                       <DecimalLength/>
                                       <Alignment>LEFT</Alignment>
                                       <StartPos>0</StartPos>
                                       <Length>0</Length>
                                       <DefaultValue>PAYMENT</DefaultValue>
                                       <Identifier>1</Identifier>
                                    </Field>
                                    <Field>
                                       <Name>ID</Name>
                                       <TagName>Identifier</TagName>
                                       <DataType>Alpha</DataType>
                                       <PaddingChar/>
                                       <DecimalLength/>
                                       <Alignment>LEFT</Alignment>
                                       <StartPos>0</StartPos>
                                       <Length>0</Length>
                                       <DefaultValue>TYPE</DefaultValue>
                                       <Identifier>1</Identifier>
                                    </Field>
                                    <Field>
                                       <Name>ID</Name>
                                       <TagName>Identifier</TagName>
                                       <DataType>Alpha</DataType>
                                       <PaddingChar/>
                                       <DecimalLength/>
                                       <Alignment>LEFT</Alignment>
                                       <StartPos>0</StartPos>
                                       <Length>0</Length>
                                       <DefaultValue>CARD</DefaultValue>
                                       <Identifier>1</Identifier>
                                    </Field>
                                    <Field>
                                       <Name>CardType</Name>
                                       <TagName>CardType</TagName>
                                       <DataType>Alpha</DataType>
                                       <PaddingChar/>
                                       <DecimalLength/>
                                       <Alignment>LEFT</Alignment>
                                       <StartPos>0</StartPos>
                                       <Length>0</Length>
                                       <DefaultValue></DefaultValue>
                                       <Identifier>0</Identifier>
                                    </Field>
                                    <Field>
                                       <Name>CardNumber</Name>
                                       <TagName>CardNumber</TagName>
                                       <DataType>Alpha</DataType>
                                       <PaddingChar/>
                                       <DecimalLength/>
                                       <Alignment>LEFT</Alignment>
                                       <StartPos>0</StartPos>
                                       <Length>0</Length>
                                       <DefaultValue></DefaultValue>
                                       <Identifier>0</Identifier>
                                    </Field>
                                 </Fields>
                              </Record>
                              <Record>
                                 <Name>PaymentDetails</Name>
                                 <TagName>PaymentDetails</TagName>
                                 <MinOccur>0</MinOccur>
                                 <MaxOccur>1</MaxOccur>
                                 <Fields>
                                    <Field>
                                       <Name>ID</Name>
                                       <TagName>Identifier</TagName>
                                       <DataType>Alpha</DataType>
                                       <PaddingChar/>
                                       <DecimalLength/>
                                       <Alignment>LEFT</Alignment>
                                       <StartPos>0</StartPos>
                                       <Length>0</Length>
                                       <DefaultValue>PAYMENT</DefaultValue>
                                       <Identifier>1</Identifier>
                                    </Field>
                                    <Field>
                                       <Name>ID</Name>
                                       <TagName>Identifier</TagName>
                                       <DataType>Alpha</DataType>
                                       <PaddingChar/>
                                       <DecimalLength/>
                                       <Alignment>LEFT</Alignment>
                                       <StartPos>0</StartPos>
                                       <Length>0</Length>
                                       <DefaultValue>TYPE</DefaultValue>
                                       <Identifier>1</Identifier>
                                    </Field>
                                    <Field>
                                       <Name>ID</Name>
                                       <TagName>Identifier</TagName>
                                       <DataType>Alpha</DataType>
                                       <PaddingChar/>
                                       <DecimalLength/>
                                       <Alignment>LEFT</Alignment>
                                       <StartPos>0</StartPos>
                                       <Length>0</Length>
                                       <DefaultValue>CASH</DefaultValue>
                                       <Identifier>1</Identifier>
                                    </Field>
                                 </Fields>
                              </Record>
                           </Records>
                        </Group>
                        <Record>
                           <Name>Date</Name>
                           <TagName>Date</TagName>
                           <MinOccur>1</MinOccur>
                           <MaxOccur>1</MaxOccur>
                           <Fields>
                              <Field>
                                 <Name>ID</Name>
                                 <TagName>Identifier</TagName>
                                 <DataType>Alpha</DataType>
                                 <PaddingChar/>
                                 <DecimalLength/>
                                 <Alignment>LEFT</Alignment>
                                 <StartPos>0</StartPos>
                                 <Length>0</Length>
                                 <DefaultValue>DATE</DefaultValue>
                                 <Identifier>1</Identifier>
                              </Field>
                              <Field>
                                 <Name>Day</Name>
                                 <TagName>Day</TagName>
                                 <DataType>Alpha</DataType>
                                 <PaddingChar/>
                                 <DecimalLength/>
                                 <Alignment>LEFT</Alignment>
                                 <StartPos>0</StartPos>
                                 <Length>0</Length>
                                 <DefaultValue></DefaultValue>
                                 <Identifier>0</Identifier>
                              </Field>
                              <Field>
                                 <Name>Month</Name>
                                 <TagName>Month</TagName>
                                 <DataType>Alpha</DataType>
                                 <PaddingChar/>
                                 <DecimalLength/>
                                 <Alignment>LEFT</Alignment>
                                 <StartPos>0</StartPos>
                                 <Length>0</Length>
                                 <DefaultValue></DefaultValue>
                                 <Identifier>0</Identifier>
                              </Field>
                              <Field>
                                 <Name>Year</Name>
                                 <TagName>Year</TagName>
                                 <DataType>Alpha</DataType>
                                 <PaddingChar/>
                                 <DecimalLength/>
                                 <Alignment>LEFT</Alignment>
                                 <StartPos>0</StartPos>
                                 <Length>0</Length>
                                 <DefaultValue></DefaultValue>
                                 <Identifier>0</Identifier>
                              </Field>
                           </Fields>
                        </Record>
                     </Records>
                     <Group>
                        <Name>Items</Name>
                        <TagName>Items</TagName>
                        <MinOccur>1</MinOccur>
                        <MaxOccur>1</MaxOccur>
                        <Records>
                           <Group>
                              <Name>Item</Name>
                              <TagName>Item</TagName>
                              <MinOccur>1</MinOccur>
                              <MaxOccur>U</MaxOccur>
                              <Records>
                                 <Record>
                                    <Name>ItemDetails</Name>
                                    <TagName>ItemDetails</TagName>
                                    <MinOccur>1</MinOccur>
                                    <MaxOccur>1</MaxOccur>
                                    <Fields>
                                       <Field>
                                          <Name>ID</Name>
                                          <TagName>Identifier</TagName>
                                          <DataType>Alpha</DataType>
                                          <PaddingChar/>
                                          <DecimalLength/>
                                          <Alignment>LEFT</Alignment>
                                          <StartPos>0</StartPos>
                                          <Length>0</Length>
                                          <DefaultValue>ITEM</DefaultValue>
                                          <Identifier>1</Identifier>
                                       </Field>
                                       <Field>
                                          <Name>Name</Name>
                                          <TagName>Name</TagName>
                                          <DataType>Alpha</DataType>
                                          <PaddingChar/>
                                          <DecimalLength/>
                                          <Alignment>LEFT</Alignment>
                                          <StartPos>0</StartPos>
                                          <Length>0</Length>
                                          <DefaultValue></DefaultValue>
                                          <Identifier>0</Identifier>
                                       </Field>
                                       <Field>
                                          <Name>Quantity</Name>
                                          <TagName>Quantity</TagName>
                                          <DataType>Alpha</DataType>
                                          <PaddingChar/>
                                          <DecimalLength/>
                                          <Alignment>LEFT</Alignment>
                                          <StartPos>0</StartPos>
                                          <Length>0</Length>
                                          <DefaultValue></DefaultValue>
                                          <Identifier>0</Identifier>
                                       </Field>
                                       <Field>
                                          <Name>Price</Name>
                                          <TagName>Price</TagName>
                                          <DataType>Alpha</DataType>
                                          <PaddingChar/>
                                          <DecimalLength/>
                                          <Alignment>LEFT</Alignment>
                                          <StartPos>0</StartPos>
                                          <Length>0</Length>
                                          <DefaultValue></DefaultValue>
                                          <Identifier>0</Identifier>
                                       </Field>
                                    </Fields>
                                 </Record>
                              </Records>
                           </Group>
                        </Records>
                     </Group>
                  </Group>
               </Records>
				</Message>
			</Messages>
		</File>
	</Files>
</BankRepository>

Input file:

CUSTOMER:Jonas:0123456:
PAYMENT:TYPE:CARD:VISA:98765432:
DATE:09:10:2002:
ITEM:Hub cap:4:199.00:
ITEM:Tyre:4:679.00:
ITEM:Fuzzy dice:1:37.50:
CUSTOMER:Magnus:1234567:
PAYMENT:TYPE:CASH:
DATE:10:10:2002:
ITEM:SAAB Oil pump:1:1229.00:
ITEM:SAAB Oil filter:1:56.00:

The expected result is:

<PurchasedItems>
	<Purchase>
		<CustomerDetails>
			<Identifier>CUSTOMER</Identifier>
			<Name>Jonas</Name>
			<Number>0123456</Number>
		</CustomerDetails>
		<Payment>
			<PaymentDetails>
				<Identifier>PAYMENT</Identifier>
				<Identifier>TYPE</Identifier>
				<Identifier>CARD</Identifier>
				<CardType>VISA</CardType>
				<CardNumber>98765432</CardNumber>
			</PaymentDetails>
		</Payment>
		<Date>
			<Identifier>DATE</Identifier>
			<Day>09</Day>
			<Month>10</Month>
			<Year>2002</Year>
		</Date>
		<Items>
			<Item>
				<ItemDetails>
					<Identifier>ITEM</Identifier>
					<Name>Hub cap</Name>
					<Quantity>4</Quantity>
					<Price>199.00</Price>
				</ItemDetails>
			</Item>
			<Item>
				<ItemDetails>
					<Identifier>ITEM</Identifier>
					<Name>Tyre</Name>
					<Quantity>4</Quantity>
					<Price>679.00</Price>
				</ItemDetails>
			</Item>
			<Item>
				<ItemDetails>
					<Identifier>ITEM</Identifier>
					<Name>Fuzzy dice</Name>
					<Quantity>1</Quantity>
					<Price>37.50</Price>
				</ItemDetails>
			</Item>
		</Items>
	</Purchase>
	<Purchase>
		<CustomerDetails>
			<Identifier>CUSTOMER</Identifier>
			<Name>Magnus</Name>
			<Number>1234567</Number>
		</CustomerDetails>
		<Payment>
			<PaymentDetails>
				<Identifier>PAYMENT</Identifier>
				<Identifier>TYPE</Identifier>
				<Identifier>CASH</Identifier>
			</PaymentDetails>
		</Payment>
		<Date>
			<Identifier>DATE</Identifier>
			<Day>10</Day>
			<Month>10</Month>
			<Year>2002</Year>
		</Date>
		<Items>
			<Item>
				<ItemDetails>
					<Identifier>ITEM</Identifier>
					<Name>SAAB Oil pump</Name>
					<Quantity>1</Quantity>
					<Price>1229.00</Price>
				</ItemDetails>
			</Item>
			<Item>
				<ItemDetails>
					<Identifier>ITEM</Identifier>
					<Name>SAAB Oil filter</Name>
					<Quantity>1</Quantity>
					<Price>56.00</Price></ItemDetails>
			</Item>
		</Items>
	</Purchase>
</PurchasedItems>

Example 13 B

This example shows how a field and record-separated flat file without identifiers is transformed to XML.

Link Flat File Definition:

<BankRepository>
	<Files>
		<File>
			<ID>SampleThirteenB</ID>
			<Messages>
				<Message><IgnorePrecedingFieldSeparator>1</IgnorePrecedingFieldSeparator>
             <DefaultEmptyFieldValue><Numeric>0</Numeric><Alpha></Alpha></DefaultEmptyFieldValue>
             <DefaultAlignment><Numeric>RIGHT</Numeric><Alpha>LEFT</Alpha></DefaultAlignment>
             <DefaultPadding><Numeric>0</Numeric><Alpha> </Alpha></DefaultPadding>
             <DefaultTrim><Numeric>1</Numeric><Alpha>0</Alpha></DefaultTrim>
					<Name>TopNode</Name>
					<TagName>TopNode</TagName>
					
					
					<EscapeChar/>
					<RecordSeparator>crlf</RecordSeparator>
					<FieldSeparator></FieldSeparator>
					<Records>
						<Group>
							<Name>People</Name>
							<TagName>People</TagName>
							<MinOccur>1</MinOccur>
							<MaxOccur>1</MaxOccur>
							<Records>
								<Group>
									<Name>Person</Name>
									<TagName>Person</TagName>
									<MinOccur>1</MinOccur>
									<MaxOccur>0</MaxOccur>
									<Records>
										<Record>
											<Name>PersonDetails</Name>
											<TagName>PersonDetails</TagName>
											<MinOccur>1</MinOccur>
											<MaxOccur>1</MaxOccur>
											<Fields>
												<Field>
													<Name>FirstName</Name>
													<TagName>FirstName</TagName>
													<DataType>Alpha</DataType>
													<PaddingChar/>
													<DecimalLength/>
													<Alignment>LEFT</Alignment>
													<StartPos>1</StartPos>
													<Length>10</Length>
													<DefaultValue></DefaultValue>
													<Identifier>0</Identifier>
												</Field>
												<Field>
													<Name>LastName</Name>
													<TagName>LastName</TagName>
													<DataType>Alpha</DataType>
													<PaddingChar/>
													<DecimalLength/>
													<Alignment>LEFT</Alignment>
													<StartPos>11</StartPos>
													<Length>10</Length>
													<DefaultValue></DefaultValue>
													<Identifier>0</Identifier>
												</Field>
												<Field>
													<Name>Organization</Name>
													<TagName>Organization</TagName>
													<DataType>Alpha</DataType>
													<PaddingChar/>
													<DecimalLength/>
													<Alignment>LEFT</Alignment>
													<StartPos>21</StartPos>
													<Length>10</Length>
													<DefaultValue></DefaultValue>
													<Identifier>0</Identifier>
												</Field>
												<Field>
													<Name>E-Mail</Name>
													<TagName>EMail</TagName>
													<DataType>Alpha</DataType>
													<PaddingChar/>
													<DecimalLength/>
													<Alignment>LEFT</Alignment>
													<StartPos>31</StartPos>
													<Length>40</Length>
													<DefaultValue></DefaultValue>
													<Identifier>0</Identifier>
												</Field>
											</Fields>
										</Record>
										<Group>
											<Name>Address</Name>
											<TagName>Address</TagName>
											<MinOccur>0</MinOccur>
											<MaxOccur>1</MaxOccur>
											<Records>
												<Record>
													<Name>AddressLine</Name>
													<TagName>AddressLine</TagName>
													<MinOccur>1</MinOccur>
													<MaxOccur>0</MaxOccur>
													<Fields>
														<Field>
															<Name>Text</Name>
															<TagName>Text</TagName>
															<DataType>Alpha</DataType>
															<PaddingChar/>
															<DecimalLength/>
															<Alignment>LEFT</Alignment>
															<StartPos>0</StartPos>
															<Length>40</Length>
															<DefaultValue></DefaultValue>
															<Identifier>0</Identifier>
														</Field>
													</Fields>
												</Record>
											</Records>
										</Group>
									</Records>
								</Group>
							</Records>
						</Group>
					</Records>
				</Message>
			</Messages>
		</File>
	</Files>
</BankRepository>

The input is a field and record-separated file without identifiers:

1234567890123456789012345678901234567890123456789012345678901234567890
Jonas Fügedi IRD jonas.fugedi@infor.se
Vendevägen 89
181 82 Danderyd
Joakim Hemligt HEM joakim.hemligt@infor.se
Vendevägen 89
Magnus Persson ICS magnus.persson@infor.se
Vendevägen 89

The expected result is:

<TopNode>
	<People>
		<Person>
			<PersonDetails>
				<FirstName>1234567890</FirstName>
				<LastName>1234567890</LastName>
				<Organization>1234567890</Organization>
				<EMail>1234567890123456789012345678901234567890</EMail>
			</PersonDetails>
		</Person>
		<Person>
			<PersonDetails>
				<FirstName>Jonas</FirstName>
				<LastName>Fügedi</LastName>
				<Organization>IRD</Organization>
				<EMail>jonas.fugedi@intentia.se</EMail>
			</PersonDetails>
			<Address>
				<AddressLine>
					<Text>Vendevägen 89</Text>
				</AddressLine>
				<AddressLine>
					<Text>181 82 Danderyd</Text>
				</AddressLine>
			</Address>
		</Person>
		<Person>
			<PersonDetails>
				<FirstName>Joakim</FirstName>
				<LastName>Hemligt</LastName>
				<Organization>HEM</Organization>
				<EMail>joakim.hemligt@intentia.se</EMail>
			</PersonDetails>
			<Address>
				<AddressLine>
					<Text>Vendevägen 89</Text>
				</AddressLine>
			</Address>
		</Person>
		<Person>
			<PersonDetails>
				<FirstName>Magnus</FirstName>
				<LastName>Persson</LastName>
				<Organization>ICS</Organization>
				<EMail>magnus.persson@intentia.se</EMail>
			</PersonDetails>
			<Address>
				<AddressLine>
					<Text>Vendevägen 89</Text>
				</AddressLine>
			</Address>
		</Person>
	</People>
</TopNode>