In this article, I shall attempt to explain flat file schema structures with optional records. In other words, I will explain how to create a flat file schema which has a option record, which can appear 0 or more times.
In case you are a newbie to these flat file structures, please read the following articles on Flat file schemas...
Flat File Structure - Quick Intro
A flat file, unlike an XML file, does not have any visible inherent structure. A flat file's structure is evident from its usage and also requires some domain knowledge to understand its representation. A flat file structure is of several types:
- Delimited flat file
- Positional flat file
- A flat file with combination of Delimited and Positional records
Consider an example flat file shown below in which the lines starting with "
810DTL" and "
810TOT" are optional.
Example - A complex positional flat file:
810HDR Invoice 1972-05-12John Doe
810DTL 01-2304040200 $2.34
810DTL 02-4030400400 $1.34
810TOT 600 $1004
The Data Dictionary for the Flat File
810HDR (Total = 50 characters)
- Header ID - 10 characters
- Description - 10 Characters
- Date of Birth - 10 Characters
- Full Name - 20 Characters
810DTL (Total = 40 characters) - OPTIONAL (occurs 0 or more times)
- Detail ID - 10 characters
- Part No - 10 characters
- Quantity - 10 characters
- Price per unit- 10 characters
810TOT (Total = 30 characters) - OPTIONAL (occurs 0 or 1 time)
- Total ID - 10 characters
- TotalQuantity - 10 characters
- TotalPrice - 10 characters
810END (Total = 20 characters)
- END ID - 10 characters
- ClerkName - 10 characters
Notice that the "
810DTL" and "
810TOT" records are OPTIONAL.
New BizTalk Server Project in Visual Studio 2005
Create a new BizTalk Server Project in Visual Studio 2005.
Step 1: In the Visual Studio 2005 menu, select the File -> New -> Project -> and select "Empty BizTalk Server Project" and type the name "
Step 2: In the Solution Explorer, right click on the project name "
FFSchemaDemo" and select Add -> New Item. In the "Add New Item" dialog box, select the "Flat File Schema" and type the Name as "FFSchema_Group.xsd". Create the structure as shown in the screen shot.
Step 3: Note the use of "
Sequence" tag to specify optional records. A "
Sequence" element can be used to specify whether an element is optional or not.
Step 4: Observe the properties of the
DTL element which specify the "Min Occurs" and the "Max Occurs" properties.
"Choice" XSD Element
The same functionality can also be obtained by using a "
Choice" element. Please observe the use of the
Observe the properties being set on the
Choice element. The value of Max Occurs is "
*" which means that the number of nodes coming out from the
Choice element is unlimited.
Schema Instance Validation
Once the schema has been created, validate the instance of the schema by right clicking on the file and selecting "Validate Instance" menu option. Verify the output file generated.
About the Downloadable Code
- Unzip the zip file in the
- The flat file sample is placed in the
FlatFilesInput directory in the zip file.
- 6th April, 2006: Initial post