Escape character

This example shows flat file to XML transformation in which the effect of a field or record separator that occurs as data in the input flat file is negated using an escape character prefix. The escape sequence is included in the data.

These are typical issues encountered with escape sequences:

  • Escapewithafixed length is not tested.

  • If XML data contains a separator as data, the parser will not escape the separator and an incorrect flat file is generated.

Flat File Definition:

<BankRepository>
	<Files>
		<File>
			<ID>SampleTen</ID>
			<Messages>
				<Message>
               <IgnorePrecedingFieldSeparator>0</IgnorePrecedingFieldSeparator>
               <DefaultEmptyFieldValue>
                  <Numeric></Numeric>
                  <Alpha></Alpha>
                </DefaultEmptyFieldValue>
                <DefaultAlignment>
                  <Numeric>RIGHT</Numeric>
                  <Alpha>LEFT</Alpha>
                </DefaultAlignment>
                <DefaultPadding>
                  <Numeric></Numeric>
                  <Alpha></Alpha>
                </DefaultPadding>
                <DefaultTrim>
                  <Numeric>0</Numeric>
                  <Alpha>0</Alpha>
                </DefaultTrim>
					<Name>TopNode</Name>
					<TagName>TopNode</TagName>										
					<EscapeChar>++</EscapeChar>
					<RecordSeparator>\n</RecordSeparator>
					<FieldSeparator>:</FieldSeparator>
					<Records>
						<Record>
							<Name>RecordOne</Name>
							<TagName>RecordOne</TagName>
							<MinOccur>1</MinOccur>
							<MaxOccur>0</MaxOccur>
							<Fields>
								<Field>
									<Name>Field1</Name>
									<TagName>Field1</TagName>
									<DataType>Alpha</DataType>
									<PaddingChar/>
									<DecimalLength/>
									<Alignment>LEFT</Alignment>
									<StartPos>0</StartPos>
									<Length>0</Length>
									<DefaultValue></DefaultValue>
									<Identifier>0</Identifier>
								</Field>
								<Field>
									<Name>Field2</Name>
									<TagName>Field2</TagName>
									<DataType>Alpha</DataType>
									<PaddingChar/>
									<DecimalLength/>
									<Alignment>LEFT</Alignment>
									<StartPos>0</StartPos>
									<Length>0</Length>
									<DefaultValue></DefaultValue>
									<Identifier>0</Identifier>
								</Field>
							</Fields>
						</Record>
					</Records>
				</Message>
			</Messages>
		</File>
	</Files>
</BankRepository>

Input File:

aa++:aa:bb++:bb:
cc++::dd++::
++:ee:++:ff:
g:h:
i:++
j:

The expected result is:

<TopNode>	
   <RecordOne>		
       <Field1>aa:aa</Field1>		
       <Field2>bb:bb</Field2>	
   </RecordOne>	
   <RecordOne>		
       <Field1>cc:</Field1>		
       <Field2>dd:</Field2>	
   </RecordOne>
   <RecordOne>		
       <Field1>:ee</Field1>		
       <Field2>:ff</Field2>	
   </RecordOne>
   <RecordOne>		
       <Field1>g</Field1>		
       <Field2>h</Field2>	
  </RecordOne>	
  <RecordOne>		
       <Field1>i</Field1>		
       <Field2>++j:</Field2>	
  </RecordOne>
</TopNode>