I am trying to import a flat file into a SQL Database via Biztalk 2006 R2. The input file has a layout as follows with each line separated by CR/LF with an extra trailing CR/LF at the end:
00(29characters after) <=== Header
07(997characters after) <=== Record Type 07 (unbounded, 0-?? possible records)
08(86characters after) <=== Record Type 08 (unbounded, 0-?? possible records)
09(89characters after) <=== Record Type 09 (unbounded, 0-?? possible records)
10(94characters after) <=== Record Type 10 (unbounded, 0-?? possible records)
16(35characters after) <=== Group Footer
17(30characters after) <=== File Footer
Anyway, i ran the Flat File Wizard, and it created an XML, but even with "Repeating Records" selected, it set the min and max occurrences of 07,08,09 and 10. I changed the min to 0 and the max to unbounded. Now, no matter what i do, i get the Unexpected data found while looking for:'\r\n' error when validating. I've tried setting the Default Child Order to Postfix and the Child Order of the root to Infix and Postfix both. Nothing seems to help.
Creating the Schema from Scratch
I think using the Flat File Schema Wizard even for moderately complex structures, like this one, is not worth the trouble. My suggestion, is to think about the overall structure, and provide an outline using the Schema Editor.
So, you example calls for a schema that has the following structure :
A single
Header
record typed00
, followed by a sequence of records typed07
,08
,09
and10
respectively. Each typed record is a structure in and of itself, which contains any number of repeating records. Finally, the structure ends with a singleGroupTrailer
record typed16
, followed by an overallTrailer
record, typed17
.This maps nicely to the following schema in BizTalk :
Now, you need to tweak various properties of the nodes in order to instruct the Flat File Disassembler how to parse your incoming messages.
Root Record
The
Root
record is just there to group the various child records together and is required for a properly structured XML document. However, it does not participate in the parsing of the incoming structure.Therefore, you should set the
Child Delimiter Type
toNone
.Header, GroupTrailer and Trailer Records
The
Header
,GroupTrailer
andTrailer
records each occur a single time, so leave theirMin Occurs
andMax Occurs
properties to their default value of1
.Furthermore, each of these records are identified by an appropriate
Tag Identifier
of00
,16
and17
respectively.Finally, those records each end with a trailing CR/LF pair or characters. Therefore, set their
Child Delimiter Type
properties toHexadecimal
, and theirChild Order
properties toPostfix
.Type07, Type08, Type09 and Type10 Structures
This is the tricky part.
One way to look at those structures is that they contain repeating records, each delimited with a trailing CR/LF. However, the structures themselves appear only once.
Another important point is that you only need a single CR/LF pair as a delimiter for both the structures and their child records. So, the settings of the
Child Delimiter Type
properties should reflect that.For the
Type07
,Type08
,Type09
andType10
records, leave the default settings. That is, set theChild Delimiter Type
property toNone
and theChild Order
property toConditional Default
. In particular, there is noTag Identifier
set for these records.Type07_Record, Type08_Record, Type09_Record and Type10_Record Structures
However, the
Type07_Record
,Type08_Record
,Type09_Record
andType10_Record
are set to occur multiple times. Set theirMin Occurs
properties to0
andMax Occurs
properties tounbounded
.Additionnaly, each repeating record ends with a trailing CR/LF pair. Therefore, set their
Child Delimiter Type
properties toHexadecimal
, theirChild Order
properties toPostfix
and theirChild Delimiter
properties to0x0D 0x0A
.Reference
For reference, the resulting settings are :
Root
: Delimited, None, Conditional Default.Header
: Delimited, Hexadecimal,0x0D 0x0A
, Postfix, Tag Identifier00
.<Sequence>
: (optional), MinOccurs: 1, MaxOccurs: 1Type07
: Delimited, None, Conditional Default.Type07_Record
: Delimited, Hexadecimal,0x0D 0x0A
, Postfix, Tag Identifier07
.Type08
: Delimited, None, Conditional Default.Type08_Record
: Delimited, Hexadecimal,0x0D 0x0A
, Postfix, Tag Identifier08
.Type09
: Delimited, None, Conditional Default.Type09_Record
: Delimited, Hexadecimal,0x0D 0x0A
, Postfix, Tag Identifier09
.Type10
: Delimited, None, Conditional Default.Type10_Record
: Delimited, Hexadecimal,0x0D 0x0A
, Postfix, Tag Identifier10
.GroupTrailer
: Delimited, Hexadecimal,0x0D 0x0A
, Postfix, Tag Identifier16
.Trailer
: Delimited, Hexadecimal,0x0D 0x0A
, Postfix, Tag Identifier17
.