XSD element to to fetch Element Based on Starting and Ending Position - xsd

28169 199855888107336BAP05185 2850204722
38169 19985588810733600001BAP05185 2850204722
This is my file data and I want to create xsd schema that fetch value from 20 to 28 character number.

In BizTalk the following Flat Files schema would parse it, Field2 containing what you are after.
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch2.SO72451573" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch2.SO72451573" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<b:schemaInfo standard="Flat File" root_reference="Root" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" />
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Root">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" child_order="postfix" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element maxOccurs="unbounded" name="Record">
<xs:annotation>
<xs:appinfo>
<b:recordInfo sequence_number="1" structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Field1" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" pos_length="19" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Field2" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="2" justification="left" pos_length="9" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element maxOccurs="unbounded" name="Field" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="3" justification="left" pos_length="1" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Would parse it into the following XML
<Root xmlns="http://Scratch2.SO72451573">
<Record xmlns="">
<Field1>28169 199855</Field1>
<Field2>888107336</Field2>
<Field>B</Field>
<Field>A</Field>
<Field>P</Field>
<Field>0</Field>
<Field>5</Field>
<Field>1</Field>
<Field>8</Field>
<Field>5</Field>
<Field/>
<Field/>
<Field/>
<Field/>
<Field>2</Field>
<Field>8</Field>
<Field>5</Field>
<Field>0</Field>
<Field>2</Field>
<Field>0</Field>
<Field>4</Field>
<Field>7</Field>
<Field>2</Field>
<Field>2</Field>
<Field/>
</Record>
<Record xmlns="">
<Field1>38169 199855</Field1>
<Field2>888107336</Field2>
<Field>0</Field>
<Field>0</Field>
<Field>0</Field>
<Field>0</Field>
<Field>1</Field>
<Field>B</Field>
<Field>A</Field>
<Field>P</Field>
<Field>0</Field>
<Field>5</Field>
<Field>1</Field>
<Field>8</Field>
<Field>5</Field>
<Field/>
<Field/>
<Field/>
<Field/>
<Field>2</Field>
<Field>8</Field>
<Field>5</Field>
<Field>0</Field>
<Field>2</Field>
<Field>0</Field>
<Field>4</Field>
<Field>7</Field>
<Field>2</Field>
<Field>2</Field>
</Record>
</Root>

Related

Biztalk Debatch flat file with header, 2 repeating records and trailer with tag identifiers

i have a flat file with header and trailers with Tag Identifiers as APTHDR and APTDTL respectively.
The current file has me miffed however, as it has a repeating record issue.
File Structure:
20data for the summary information
HE Header of record
DE Detail of record
HE Header of record
DE Detail of record
DE Detail of record
20 trailler data
record 20 = one instance for summary, one instance for trailler
record.
record HE: one HE have multiple DE. one file have multiple HE.
this is the data example:
20201117125512HH 001APPOINTMENT DATA 85372
HE0350100000001 1 2CROS04202020-11-25012020-11-25 15:30:00.000000 PIC077120 128027 2020-11-17 12:50:52.000265 N N 0000004390000000000186000000 00000 PIC077120 023095412
DE035010000000C116780360635000000439PIC077120 023095412
HE0350100000001 1 2CACG05002020-11-25012020-11-25 14:00:00.000000 3501382191/, 183699 2020-11-17 12:51:02.000864 N Y NS0000013210083300043754000000 00000 3501382191/, 1621476023035082
DE035010000000C3100203821910000010013501382191/, 1621476023035082
DE035010000000C3100202566840000001003501382191/, 1621476023035082
DE035010000000C3100203826550000001073501382191/, 1621476023035082
DE035010000000C3100203852630000000203501382191/, 1621476023035082
DE035010000000C3100203746790000000183501382191/, 1621476023035082
DE035010000000C3100202903510000000753501382191/, 1621476023035082
20201117125512TT 001000000000000000000110000000000
I get the results in the correct placement if I use a single set, but once I try to create a multiple record file it get hosed.
I just have no idea how to fix it.
Thanks!
First of all you need to create 3 schemas, a Header, a Body and a Trailer.
Split the file you have into those components so you can test each schema against that part, for the body just have the one HE and multiple DE.
Then you need to create a pipeline with a flat file disassemble component and set all three schema in the properties.
Deploy these, create a receive port and location that uses the pipeline, and have something subscribing to the messages.
Example schemas
Header schema
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.SO68310662" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.SO68310662" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<b:schemaInfo standard="Flat File" root_reference="Header" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" />
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Header">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" child_order="postfix" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="HeaderRecord">
<xs:annotation>
<xs:appinfo>
<b:recordInfo sequence_number="1" structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="DateTime">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_length="14" sequence_number="1" />
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string" />
</xs:simpleType>
</xs:element>
<xs:element name="Field" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_length="64" sequence_number="2" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Body Schema
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.SO68310662" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.SO68310662" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<b:schemaInfo standard="Flat File" root_reference="Body" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" />
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Body">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" child_order="postfix" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="HeaderRecord">
<xs:annotation>
<xs:appinfo>
<b:recordInfo sequence_number="1" structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name=" HE" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Field1" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_length="263" sequence_number="1" pos_offset="3" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="unbounded" name="DetailRecord">
<xs:annotation>
<xs:appinfo>
<b:recordInfo sequence_number="2" structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name=" DE" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Field1" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="1" pos_length="63" pos_offset="3" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Trailer schema
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.SO68310662" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.SO68310662" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<b:schemaInfo standard="Flat File" root_reference="Header" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" />
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Header">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" child_order="postfix" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="TrailerRecord">
<xs:annotation>
<xs:appinfo>
<b:recordInfo sequence_number="1" structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="DateTime">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_length="14" sequence_number="1" pos_offset="1" />
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string" />
</xs:simpleType>
</xs:element>
<xs:element name="Field" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_length="37" sequence_number="2" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Output message 1
<Body xmlns="http://Scratch.SO68310662">
<HeaderRecord xmlns="">
<Field1>0350100000001 1 2CACG05002020-11-25012020-11-25 14:00:00.000000 3501382191/, 183699 2020-11-17 12:51:02.000864 N Y NS0000013210083300043754000000 00000 3501382191/, 1621476023035082</Field1>
</HeaderRecord>
<DetailRecord xmlns="">
<Field1>035010000000C3100203821910000010013501382191/, 1621476023035082</Field1>
</DetailRecord>
<DetailRecord xmlns="">
<Field1>035010000000C3100202566840000001003501382191/, 1621476023035082</Field1>
</DetailRecord>
<DetailRecord xmlns="">
<Field1>035010000000C3100203826550000001073501382191/, 1621476023035082</Field1>
</DetailRecord>
<DetailRecord xmlns="">
<Field1>035010000000C3100203852630000000203501382191/, 1621476023035082</Field1>
</DetailRecord>
<DetailRecord xmlns="">
<Field1>035010000000C3100203746790000000183501382191/, 1621476023035082</Field1>
</DetailRecord>
<DetailRecord xmlns="">
<Field1>035010000000C3100202903510000000753501382191/, 1621476023035082</Field1>
</DetailRecord>
</Body>
Output message 2
<Body xmlns="http://Scratch.SO68310662">
<HeaderRecord xmlns="">
<Field1>0350100000001 1 2CROS04202020-11-25012020-11-25 15:30:00.000000 PIC077120 128027 2020-11-17 12:50:52.000265 N N 0000004390000000000186000000 00000 PIC077120 023095412</Field1>
</HeaderRecord>
<DetailRecord xmlns="">
<Field1>035010000000C116780360635000000439PIC077120 023095412</Field1>
</DetailRecord>
</Body>

Schema for Flat File

I have to do to a transformation from flatfile to xml but the problem is that the flatfile has multiple child nodes and the child nodes have sub nodes as well. The records are occuring multiple times in the file. I had created a schema but it processes only single record.
Can you please tell me the structure of the schema I should create that can process mulitple records.
Here is the flat file.
ASN,000589,,0000768,
HDR,0008289,0040294A,LA,00,1570,21,TM,,,M,PE,Corporation,120276,052451,05-00289,05-08299,02,LA,B,011,C,BD ,8,LA,16570,24,ST,,N,GETRO,GETRO,120246,054551,LA,0000568,8018279,
POH,0508289,004024A,1,PPO000199,LA,NP,00,13615,13563,13414,1351,2584,,3598,2900,,,A200,B200,HN,18552,1270,,N,GETRO,GETRO,1206,05451,LA,0000768,
LNE,0005289,00402929 ,1,1,PPO000099,AP,00,8719,00704,2536,DW,3870,DW,CC,0930-01,05-08289,,N,GETRO,GETRO,13246,05751,LA,00005668,2,
PCK,A0722,4786149,100,2536,LA,
LNE,0005089,0040294A ,2,1,PPO0000199,OP,00,82664,001822,890,HW,3500,HW,CC,0656-01,05-08289,,N,GETRO,GETRO,120246,054551,LA,000052768,4,
PCK,031992,48005,12,8290,LA,
LNE,0005289,004029A ,2,2,PPO0000199,AP,00,872087,0000859,5744,HN,367500,HW,CD,098656-02,05-08289,,N,GETRO,GETRO,120246,054551,LA,00005768,3,
PCK,04022,479782,100,2872,LA,
PCK,04023,4797288,100,2872,LA,
ASN,000521288,004679294A,000075667,
HDR,000788288,004024594A,LA,00,33758,01,TM,,,M,PP,Corporation,120246,054551,05-08289,05-08289,01,LA,B,011,C,BA ,8,LA,33158,24,ST,,N,GETRO,GETRO,120246,054551,LA,000672767,8056279,
POH,000508288,004029294A,1,PPO000000199,LA,AP,00,1360415,1350063,1346914,13501,258304,,35698,2900,,,D250,D290,HQ,10352,33158,,N,GETRO,GETRO,120246,054551,LA,000052767,
LNE,0005288,0040294A ,1,2,PPO0000199,OP,00,874402,30001281,33158,HA,377500,HA,CC,098630-02,05-08289,,N,GETRO,GETRO,120246,054551,LA,00002767,1,
PCK,03134,480075,12,8290,LA,
PCK,03114,480076,12,8290,LA,
PCK,94985,480579,12,8290,LA,
PCK,94995,480080,12,8290,LA,
Here is the schema I have created
<?xml version="1.0" encoding="UTF-16"?>
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://Test.InputSchema" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://Test.InputSchema">
-<xs:annotation>
-<xs:appinfo>
<schemaEditorExtension:schemaInfo xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" standardName="Flat File" extensionClass="Microsoft.Azure.Integration.DesignTools.FlatFileExtension.FlatFileExtension" namespaceAlias="b"/>
<b:schemaInfo root_reference="Root" default_child_order="infix" default_child_delimiter="," child_delimiter_type="char" compile_parse_tables="false" allow_message_breakup_of_infix_root="false" early_terminate_optional_fields="false" allow_early_termination="false" generate_empty_nodes="true" suppress_empty_nodes="false" lookahead_depth="3" parser_optimization="speed" count_positions_by_byte="false" pad_char_type="char" default_pad_char=" " codepage="65001" standard="Flat File"/>
</xs:appinfo>
</xs:annotation>
-<xs:element name="Root">
-<xs:annotation>
-<xs:appinfo>
<b:recordInfo child_delimiter_type="hex" suppress_trailing_delimiters="false" preserve_delimiter_for_empty_data="true" sequence_number="1" child_order="postfix" child_delimiter="0x0D 0x0A" structure="delimited"/>
</xs:appinfo>
</xs:annotation>
-<xs:complexType>
-<xs:sequence>
-<xs:annotation>
-<xs:appinfo>
<b:groupInfo sequence_number="0"/>
</xs:appinfo>
</xs:annotation>
-<xs:sequence maxOccurs="unbounded">
-<xs:annotation>
-<xs:appinfo>
<b:groupInfo sequence_number="1"/>
</xs:appinfo>
</xs:annotation>
-<xs:element name="ASN">
-<xs:annotation>
-<xs:appinfo>
<b:recordInfo child_delimiter_type="default" suppress_trailing_delimiters="false" preserve_delimiter_for_empty_data="true" sequence_number="1" child_order="default" structure="delimited" tag_name="ASN,"/>
</xs:appinfo>
</xs:annotation>
-<xs:complexType>
-<xs:sequence>
-<xs:annotation>
-<xs:appinfo>
<b:groupInfo sequence_number="0"/>
</xs:appinfo>
</xs:annotation>
-<xs:element name="Field" maxOccurs="unbounded" type="xs:string">
-<xs:annotation>
-<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
-<xs:element name="HDR">
-<xs:annotation>
-<xs:appinfo>
<b:recordInfo child_delimiter_type="default" suppress_trailing_delimiters="false" preserve_delimiter_for_empty_data="true" sequence_number="2" child_order="default" structure="delimited" tag_name="HDR,"/>
</xs:appinfo>
</xs:annotation>
-<xs:complexType>
-<xs:sequence>
-<xs:annotation>
-<xs:appinfo>
<b:groupInfo sequence_number="0"/>
</xs:appinfo>
</xs:annotation>
-<xs:element name="Field" maxOccurs="unbounded" type="xs:string">
-<xs:annotation>
-<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
-<xs:element name="POH">
-<xs:annotation>
-<xs:appinfo>
<b:recordInfo child_delimiter_type="default" suppress_trailing_delimiters="false" preserve_delimiter_for_empty_data="true" sequence_number="3" child_order="default" structure="delimited" tag_name="POH,"/>
</xs:appinfo>
</xs:annotation>
-<xs:complexType>
-<xs:sequence>
-<xs:annotation>
-<xs:appinfo>
<b:groupInfo sequence_number="0"/>
</xs:appinfo>
</xs:annotation>
-<xs:element name="Field" maxOccurs="unbounded" type="xs:string">
-<xs:annotation>
-<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
-<xs:sequence maxOccurs="unbounded">
-<xs:annotation>
-<xs:appinfo>
<b:groupInfo sequence_number="4"/>
</xs:appinfo>
</xs:annotation>
-<xs:element name="LNE" maxOccurs="unbounded">
-<xs:annotation>
-<xs:appinfo>
<b:recordInfo child_delimiter_type="default" suppress_trailing_delimiters="false" preserve_delimiter_for_empty_data="true" sequence_number="1" child_order="default" structure="delimited" tag_name="LNE,"/>
</xs:appinfo>
</xs:annotation>
-<xs:complexType>
-<xs:sequence>
-<xs:annotation>
-<xs:appinfo>
<b:groupInfo sequence_number="0"/>
</xs:appinfo>
</xs:annotation>
-<xs:element name="Field" maxOccurs="unbounded" type="xs:string">
-<xs:annotation>
-<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
-<xs:element name="PCK">
-<xs:annotation>
-<xs:appinfo>
<b:recordInfo child_delimiter_type="default" suppress_trailing_delimiters="false" preserve_delimiter_for_empty_data="true" sequence_number="2" child_order="default" structure="delimited" tag_name="PCK,"/>
</xs:appinfo>
</xs:annotation>
-<xs:complexType>
-<xs:sequence>
-<xs:annotation>
-<xs:appinfo>
<b:groupInfo sequence_number="0"/>
</xs:appinfo>
</xs:annotation>
-<xs:element name="Field" maxOccurs="unbounded" type="xs:string">
-<xs:annotation>
-<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Here is a schema that parses the records correctly which uses both Tag Identifier and Sequence Groups. I have not defined all the fields, but just put a repeating field under each record which you can replace with the proper fields.
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.SO64697726" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.SO64697726" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<b:schemaInfo standard="Flat File" root_reference="Root" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="complexity" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" child_delimiter_type="char" default_child_delimiter="," default_child_order="infix" />
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Root">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" child_order="postfix" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:sequence maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="1" />
</xs:appinfo>
</xs:annotation>
<xs:element maxOccurs="unbounded" name="ASN">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="ASN," child_delimiter_type="default" child_order="default" sequence_number="1" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element maxOccurs="unbounded" name="Field" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="HDR">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" repeating_delimiter_type="char" child_delimiter_type="default" child_order="default" tag_name="HDR," sequence_number="2" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element maxOccurs="unbounded" name="Field" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="POH">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" repeating_delimiter_type="char" child_delimiter_type="default" child_order="default" tag_name="POH," sequence_number="3" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element maxOccurs="unbounded" name="Field" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:sequence maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="4" />
</xs:appinfo>
</xs:annotation>
<xs:element maxOccurs="unbounded" name="LNE">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" repeating_delimiter_type="char" child_delimiter_type="default" child_order="default" tag_name="LNE," sequence_number="1" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element maxOccurs="unbounded" name="Field" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="unbounded" name="PCK">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" repeating_delimiter_type="char" child_delimiter_type="default" child_order="default" tag_name="PCK," sequence_number="2" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element maxOccurs="unbounded" name="Field" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Output
<Root xmlns="http://Scratch.SO64697726">
<ASN xmlns="">
<Field>000589</Field>
<Field/>
<Field>0000768</Field>
<Field/>
</ASN>
<HDR xmlns="">
<Field>0008289</Field>
<Field>0040294A</Field>
<Field>LA</Field>
<Field>00</Field>
<Field>1570</Field>
<Field>21</Field>
<Field>TM</Field>
<Field/>
<Field/>
<Field>M</Field>
<Field>PE</Field>
<Field>Corporation</Field>
<Field>120276</Field>
<Field>052451</Field>
<Field>05-00289</Field>
<Field>05-08299</Field>
<Field>02</Field>
<Field>LA</Field>
<Field>B</Field>
<Field>011</Field>
<Field>C</Field>
<Field>BD</Field>
<Field>8</Field>
<Field>LA</Field>
<Field>16570</Field>
<Field>24</Field>
<Field>ST</Field>
<Field/>
<Field>N</Field>
<Field>GETRO</Field>
<Field>GETRO</Field>
<Field>120246</Field>
<Field>054551</Field>
<Field>LA</Field>
<Field>0000568</Field>
<Field>8018279</Field>
<Field/>
</HDR>
<POH xmlns="">
<Field>0508289</Field>
<Field>004024A</Field>
<Field>1</Field>
<Field>PPO000199</Field>
<Field>LA</Field>
<Field>NP</Field>
<Field>00</Field>
<Field>13615</Field>
<Field>13563</Field>
<Field>13414</Field>
<Field>1351</Field>
<Field>2584</Field>
<Field/>
<Field>3598</Field>
<Field>2900</Field>
<Field/>
<Field/>
<Field>A200</Field>
<Field>B200</Field>
<Field>HN</Field>
<Field>18552</Field>
<Field>1270</Field>
<Field/>
<Field>N</Field>
<Field>GETRO</Field>
<Field>GETRO</Field>
<Field>1206</Field>
<Field>05451</Field>
<Field>LA</Field>
<Field>0000768</Field>
<Field/>
</POH>
<LNE xmlns="">
<Field>0005289</Field>
<Field>00402929</Field>
<Field>1</Field>
<Field>1</Field>
<Field>PPO000099</Field>
<Field>AP</Field>
<Field>00</Field>
<Field>8719</Field>
<Field>00704</Field>
<Field>2536</Field>
<Field>DW</Field>
<Field>3870</Field>
<Field>DW</Field>
<Field>CC</Field>
<Field>0930-01</Field>
<Field>05-08289</Field>
<Field/>
<Field>N</Field>
<Field>GETRO</Field>
<Field>GETRO</Field>
<Field>13246</Field>
<Field>05751</Field>
<Field>LA</Field>
<Field>00005668</Field>
<Field>2</Field>
<Field/>
</LNE>
<PCK xmlns="">
<Field>A0722</Field>
<Field>4786149</Field>
<Field>100</Field>
<Field>2536</Field>
<Field>LA</Field>
<Field/>
</PCK>
<LNE xmlns="">
<Field>0005089</Field>
<Field>0040294A</Field>
<Field>2</Field>
<Field>1</Field>
<Field>PPO0000199</Field>
<Field>OP</Field>
<Field>00</Field>
<Field>82664</Field>
<Field>001822</Field>
<Field>890</Field>
<Field>HW</Field>
<Field>3500</Field>
<Field>HW</Field>
<Field>CC</Field>
<Field>0656-01</Field>
<Field>05-08289</Field>
<Field/>
<Field>N</Field>
<Field>GETRO</Field>
<Field>GETRO</Field>
<Field>120246</Field>
<Field>054551</Field>
<Field>LA</Field>
<Field>000052768</Field>
<Field>4</Field>
<Field/>
</LNE>
<PCK xmlns="">
<Field>031992</Field>
<Field>48005</Field>
<Field>12</Field>
<Field>8290</Field>
<Field>LA</Field>
<Field/>
</PCK>
<LNE xmlns="">
<Field>0005289</Field>
<Field>004029A</Field>
<Field>2</Field>
<Field>2</Field>
<Field>PPO0000199</Field>
<Field>AP</Field>
<Field>00</Field>
<Field>872087</Field>
<Field>0000859</Field>
<Field>5744</Field>
<Field>HN</Field>
<Field>367500</Field>
<Field>HW</Field>
<Field>CD</Field>
<Field>098656-02</Field>
<Field>05-08289</Field>
<Field/>
<Field>N</Field>
<Field>GETRO</Field>
<Field>GETRO</Field>
<Field>120246</Field>
<Field>054551</Field>
<Field>LA</Field>
<Field>00005768</Field>
<Field>3</Field>
<Field/>
</LNE>
<PCK xmlns="">
<Field>04022</Field>
<Field>479782</Field>
<Field>100</Field>
<Field>2872</Field>
<Field>LA</Field>
<Field/>
</PCK>
<PCK xmlns="">
<Field>04023</Field>
<Field>4797288</Field>
<Field>100</Field>
<Field>2872</Field>
<Field>LA</Field>
<Field/>
</PCK>
<ASN xmlns="">
<Field>000521288</Field>
<Field>004679294A</Field>
<Field>000075667</Field>
<Field/>
</ASN>
<HDR xmlns="">
<Field>000788288</Field>
<Field>004024594A</Field>
<Field>LA</Field>
<Field>00</Field>
<Field>33758</Field>
<Field>01</Field>
<Field>TM</Field>
<Field/>
<Field/>
<Field>M</Field>
<Field>PP</Field>
<Field>Corporation</Field>
<Field>120246</Field>
<Field>054551</Field>
<Field>05-08289</Field>
<Field>05-08289</Field>
<Field>01</Field>
<Field>LA</Field>
<Field>B</Field>
<Field>011</Field>
<Field>C</Field>
<Field>BA</Field>
<Field>8</Field>
<Field>LA</Field>
<Field>33158</Field>
<Field>24</Field>
<Field>ST</Field>
<Field/>
<Field>N</Field>
<Field>GETRO</Field>
<Field>GETRO</Field>
<Field>120246</Field>
<Field>054551</Field>
<Field>LA</Field>
<Field>000672767</Field>
<Field>8056279</Field>
<Field/>
</HDR>
<POH xmlns="">
<Field>000508288</Field>
<Field>004029294A</Field>
<Field>1</Field>
<Field>PPO000000199</Field>
<Field>LA</Field>
<Field>AP</Field>
<Field>00</Field>
<Field>1360415</Field>
<Field>1350063</Field>
<Field>1346914</Field>
<Field>13501</Field>
<Field>258304</Field>
<Field/>
<Field>35698</Field>
<Field>2900</Field>
<Field/>
<Field/>
<Field>D250</Field>
<Field>D290</Field>
<Field>HQ</Field>
<Field>10352</Field>
<Field>33158</Field>
<Field/>
<Field>N</Field>
<Field>GETRO</Field>
<Field>GETRO</Field>
<Field>120246</Field>
<Field>054551</Field>
<Field>LA</Field>
<Field>000052767</Field>
<Field/>
</POH>
<LNE xmlns="">
<Field>0005288</Field>
<Field>0040294A</Field>
<Field>1</Field>
<Field>2</Field>
<Field>PPO0000199</Field>
<Field>OP</Field>
<Field>00</Field>
<Field>874402</Field>
<Field>30001281</Field>
<Field>33158</Field>
<Field>HA</Field>
<Field>377500</Field>
<Field>HA</Field>
<Field>CC</Field>
<Field>098630-02</Field>
<Field>05-08289</Field>
<Field/>
<Field>N</Field>
<Field>GETRO</Field>
<Field>GETRO</Field>
<Field>120246</Field>
<Field>054551</Field>
<Field>LA</Field>
<Field>00002767</Field>
<Field>1</Field>
<Field/>
</LNE>
<PCK xmlns="">
<Field>03134</Field>
<Field>480075</Field>
<Field>12</Field>
<Field>8290</Field>
<Field>LA</Field>
<Field/>
</PCK>
<PCK xmlns="">
<Field>03114</Field>
<Field>480076</Field>
<Field>12</Field>
<Field>8290</Field>
<Field>LA</Field>
<Field/>
</PCK>
<PCK xmlns="">
<Field>94985</Field>
<Field>480579</Field>
<Field>12</Field>
<Field>8290</Field>
<Field>LA</Field>
<Field/>
</PCK>
<PCK xmlns="">
<Field>94995</Field>
<Field>480080</Field>
<Field>12</Field>
<Field>8290</Field>
<Field>LA</Field>
<Field/>
</PCK>
</Root>

How to create flat file XSD-schema for two level hierarchical data?

I am a newer in BizTalk and I must create an XSD-schema from a CSV-file:
As you can see, it includes header and orders. Every order has it's own order-header - row with name of the shop and filled Period field, but with empty Quantity, Price, Cost and Currency fields. Every order has few positions, which have filled all fields, except Period. Every order-header has ItemNumber = 0. How to create correct flat file schema in this situation?
OrderDate;OrderNumber;ItemNumber;DESCRIPTION_LONG;Quantity;Price;Cost;Period;Currency
30-04-17;9;0;Shop: McDonalds;;;;2017-04;
30-04-17;9;1;Double burger;2;5,99;11,98;;USD
30-04-17;9;2;Coca-Cola;2;2,19;4,38;;USD
30-04-17;10;0;Shop: Hunting and fishing;;;;2017-04;
30-04-17;10;1;Fishing rod;2;10,90;21,80;;USD
30-04-17;10;2;Bait;5;1,00;5,00;;USD
30-04-17;10;3;Hunting gun;1;999,00;999,00;;USD
I think the best option is parse your Flat File to an XML without trying to 'force' the final structure, as Pieter said on before answer. Something like this:
<Root xmlns="http://BizTalkMassCopy.FlatFileSchema3">
<Header xmlns="">
<HeaderOrderDate>OrderDate</HeaderOrderDate>
<HeaderOrderNumber>OrderNumber</HeaderOrderNumber>
<HeaderItemNumber>ItemNumber</HeaderItemNumber>
<HeaderDescription>DESCRIPTION_LONG</HeaderDescription>
<HeaderQuantity>Quantity</HeaderQuantity>
<HeaderPrice>Price</HeaderPrice>
<HeaderCost>Cost</HeaderCost>
<HeaderPeriod>Period</HeaderPeriod>
<HeaderCurrency>Currency</HeaderCurrency>
</Header>
<OrderItem xmlns="">
<OrderDate>30-04-17</OrderDate>
<OrderNumber>9</OrderNumber>
<ItemNumber>0</ItemNumber>
<Description>Shop: McDonalds</Description>
<Quantity></Quantity>
<Price></Price>
<Cost></Cost>
<Period>2017-04</Period>
<Currency></Currency>
</OrderItem>
<OrderItem xmlns="">
<OrderDate>30-04-17</OrderDate>
<OrderNumber>9</OrderNumber>
<ItemNumber>1</ItemNumber>
<Description>Double burger</Description>
<Quantity>2</Quantity>
<Price>5,99</Price>
<Cost>11,98</Cost>
<Period></Period>
<Currency>USD</Currency>
</OrderItem>
<OrderItem xmlns="">
<OrderDate>30-04-17</OrderDate>
<OrderNumber>9</OrderNumber>
<ItemNumber>2</ItemNumber>
<Description>Coca-Cola</Description>
<Quantity>2</Quantity>
<Price>2,19</Price>
<Cost>4,38</Cost>
<Period></Period>
<Currency>USD</Currency>
</OrderItem>
<OrderItem xmlns="">
<OrderDate>30-04-17</OrderDate>
<OrderNumber>10</OrderNumber>
<ItemNumber>0</ItemNumber>
<Description>Shop: Hunting and fishing</Description>
<Quantity></Quantity>
<Price></Price>
<Cost></Cost>
<Period>2017-04</Period>
<Currency></Currency>
</OrderItem>
<OrderItem xmlns="">
<OrderDate>30-04-17</OrderDate>
<OrderNumber>10</OrderNumber>
<ItemNumber>1</ItemNumber>
<Description>Fishing rod</Description>
<Quantity>2</Quantity>
<Price>10,90</Price>
<Cost>21,80</Cost>
<Period></Period>
<Currency>USD</Currency>
</OrderItem>
<OrderItem xmlns="">
<OrderDate>30-04-17</OrderDate>
<OrderNumber>10</OrderNumber>
<ItemNumber>2</ItemNumber>
<Description>Bait</Description>
<Quantity>5</Quantity>
<Price>1,00</Price>
<Cost>5,00</Cost>
<Period></Period>
<Currency>USD</Currency>
</OrderItem>
<OrderItem xmlns="">
<OrderDate>30-04-17</OrderDate>
<OrderNumber>10</OrderNumber>
<ItemNumber>3</ItemNumber>
<Description>Hunting gun</Description>
<Quantity>1</Quantity>
<Price>999,00</Price>
<Cost>999,00</Cost>
<Period></Period>
<Currency>USD</Currency>
</OrderItem>
</Root>
With a flat schema similar to this:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://BizTalkMassCopy.FlatFileSchema3" targetNamespace="http://BizTalkMassCopy.FlatFileSchema3" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
<b:schemaInfo standard="Flat File" codepage="65001" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" root_reference="Root" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Root">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" child_delimiter_type="hex" child_delimiter="0xD 0xA" child_order="infix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Header">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter=";" child_order="infix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
<xs:element name="HeaderOrderDate" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="1" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="HeaderOrderNumber" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="2" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="HeaderItemNumber" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="3" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="HeaderDescription" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="4" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="HeaderQuantity" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="5" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="HeaderPrice" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="6" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="HeaderCost" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="7" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="HeaderPeriod" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="8" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="HeaderCurrency" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="9" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="unbounded" name="OrderItem">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter=";" child_order="infix" sequence_number="2" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
<xs:element name="OrderDate" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="1" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="OrderNumber" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="2" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="ItemNumber" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="3" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Description" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="4" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Quantity" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="5" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Price" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="6" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Cost" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="7" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Period" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="8" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Currency" type="xs:string">
<xs:annotation>
<xs:appinfo>
<fieldInfo sequence_number="9" justification="left" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And then use a map to obtain the final result, with grouping mechanism such as Grouping in Biztalk Map Based on Multiple Elements
You might be able to do this using tag Identifiers (see https://blogs.msdn.microsoft.com/biztalknotes/2013/02/05/flat-file-schema-creation-with-tag-identifiers-in-the-input-flat-file-repeating-in-a-random-fashion/ for an example), but I'm not 100% sure this would work without issues, since the identifier (ItemNumber = 0) is not in the beginning of the line. My experience shows me the Flat file disassembler probing has limited success in those cases.
My general recommendation to people in this case would be not to try and 'force' structure in your flat file schema, since obviously your flat file structure does not have it. What I see is that each line has the same structure/format. It's only functionally different.
From that perspective I would go for a Flat File schema matching your CSV-file structure (one type of record with comma-separated fields and with a newline as a line delimiter) and, from there, map to a schema which makes more sense functionally.
My solution is,
Create a source schema for parse your flat file.
Create a destination schema for grouped result
Create a map for group your source schema.
Add this Inline XSLT Scripts to your map
For the first script functoid
<xsl:key name="groups" match="Order" use="OrderNumber"/>
For the second script functoid
<xsl:for-each select="Order[generate-id(.)=generate-id(key('groups',OrderNumber))]">
<xsl:sort select="OrderNumber" order="ascending"/>
<xsl:choose>
<xsl:when test="OrderDate != 'OrderDate'">
<Order>
<OrderDate><xsl:value-of select="OrderDate/text()" /></OrderDate>
<OrderNumber><xsl:value-of select="OrderNumber/text()" /></OrderNumber>
<Description><xsl:value-of select="Description/text()" /></Description>
<Period><xsl:value-of select="Period/text()" /></Period>
<Items>
<xsl:for-each select="key('groups',OrderNumber)">
<xsl:choose>
<xsl:when test="ItemNumber > '0'">
<Item>
<ItemNumber><xsl:value-of select="ItemNumber" /></ItemNumber>
<Quantity><xsl:value-of select="Quantity" /></Quantity>
<Price><xsl:value-of select="Price" /></Price>
<Cost><xsl:value-of select="Cost" /></Cost>
<Currency><xsl:value-of select="Currency" /></Currency>
</Item>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</Items>
</Order>
</xsl:when>
</xsl:choose>
</xsl:for-each>
Test your map and get this output.
<ns0:Orders xmlns:ns0="http://BizTalkServerTestProject.FlatFileSchema6">
<Order>
<OrderDate>30-04-17</OrderDate>
<OrderNumber>10</OrderNumber>
<Description>Shop: Hunting and fishing</Description>
<Period>2017-04</Period>
<Items>
<Item>
<ItemNumber>1</ItemNumber>
<Quantity>2</Quantity>
<Price>10,90</Price>
<Cost>21,80</Cost>
<Currency>USD</Currency>
</Item>
<Item>
<ItemNumber>2</ItemNumber>
<Quantity>5</Quantity>
<Price>1,00</Price>
<Cost>5,00</Cost>
<Currency>USD</Currency>
</Item>
<Item>
<ItemNumber>3</ItemNumber>
<Quantity>1</Quantity>
<Price>999,00</Price>
<Cost>999,00</Cost>
<Currency>USD</Currency>
</Item>
</Items>
</Order>
<Order>
<OrderDate>30-04-17</OrderDate>
<OrderNumber>9</OrderNumber>
<Description>Shop: McDonalds</Description>
<Period>2017-04</Period>
<Items>
<Item>
<ItemNumber>1</ItemNumber>
<Quantity>2</Quantity>
<Price>5,99</Price>
<Cost>11,98</Cost>
<Currency>USD</Currency>
</Item>
<Item>
<ItemNumber>2</ItemNumber>
<Quantity>2</Quantity>
<Price>2,19</Price>
<Cost>4,38</Cost>
<Currency>USD</Currency>
</Item>
</Items>
</Order>
</ns0:Orders>
You can find full source code of the schemas and the map from this URL.http://blog.sarslan.com/group-source-schema-in-a-map/

How to define a Flat file schema for a record with a repeating sequence?

I have a positional flat file which contains records with a repeating sequence, like this;
TOKEN NAME LABEL VALUE LABEL VALUE LABEL VALUE LABEL VALUE ..
The TOKEN identifies the type of record, the name is a name value, and the LABEL (10 positions) and VALUE (50 positions) pairs can repeat a not-fixed number of times (1..*).
I have defined a flat file schema as below; It contains a (1..*), with a LABEL and a VALUE with the correct positional data:
Both LABEL and VALUE have a minOccurs and a maxOccurs of 1.
The problem I have is that BizTalk does not seam to be able to handle this situation. When I generate a (native) instance for this schema I get the following output:
TOKEN NAME LABEL VALUE
(It generates only a single instance of LABEL VALUE).
When I try to read a file that has multiple occurrences of LABEL VALUE pairs (5), it gives me the following XML:
<FILE xmlns="http://schemas.demo/2015/01">
<RepeatingRecord xmlns="">
<NAME>NAME</NAME>
<LABEL>LABEL</LABEL>
<LABEL>VALUE</LABEL>
<LABEL>LABEL</LABEL>
<LABEL>VALUE</LABEL>
<LABEL>LABEL</LABEL>
<LABEL>VALUE</LABEL>
<LABEL>LABEL</LABEL>
<LABEL>VALUE</LABEL>
<LABEL>LABEL</LABEL>
<LABEL>VALUE</LABEL>
</RepeatingRecord>
</FILE>
So I only get LABEL tags, but no VALUE tags. The contents of the VALUE parts are placed wrongly in a LABEL tag.
I would expect the following XML:
<FILE xmlns="http://schemas.demo/2015/01">
<RepeatingRecord xmlns="">
<NAME>NAME</NAME>
<LABEL>LABEL</LABEL>
<VALUE>VALUE</VALUE>
<LABEL>LABEL</LABEL>
<VALUE>VALUE</VALUE>
<LABEL>LABEL</LABEL>
<VALUE>VALUE</VALUE>
<LABEL>LABEL</LABEL>
<VALUE>VALUE</VALUE>
<LABEL>LABEL</LABEL>
<VALUE>VALUE</VALUE>
</RepeatingRecord>
</FILE>
How can I define a flat file schema with a repeating sequence in the record?
I currently have the following schema:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://schemas.goudse.nl/irma/adapter/2015/01" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://schemas.goudse.nl/irma/adapter/2015/01" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<b:schemaInfo standard="Flat File" root_reference="FILE" default_pad_char="0x20" pad_char_type="hex" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="true" generate_empty_nodes="false" allow_early_termination="true" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" document_type="ASFBatchFlatFileSchema" version="2015.01" schema_type="document" default_child_order="postfix" child_delimiter_type="hex" default_child_delimiter="0x0D 0x0A" />
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
</xs:appinfo>
</xs:annotation>
<xs:element name="FILE">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" child_order="default" notes="Een compleet bestand" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element minOccurs="1" maxOccurs="unbounded" name="RepeatingRecord">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="TOKEN " notes="Data behorende bij de schadebrief" sequence_number="1" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="NAME" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" sequence_number="1" pos_length="12" pos_offset="6" pad_char_type="hex" pad_char="0x20" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="2" />
</xs:appinfo>
</xs:annotation>
<xs:element minOccurs="1" maxOccurs="1" name="LABEL" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_length="10" pad_char_type="hex" pad_char="0x20" sequence_number="1" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element minOccurs="1" maxOccurs="1" name="VALUE" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_length="50" pad_char_type="hex" pad_char="0x20" sequence_number="2" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
and the following test data file (replaced spaces with periods for clarity, the schema defines spaces for padding).
TOKEN.NAME........LABEL.....VALUE.............................................LABEL.....VALUE.............................................LABEL.....VALUE.............................................LABEL.....VALUE.............................................LABEL.....VALUE.............................................
UPDATE
What I did not mention in this question (for sake of simplicity) is that this record is used in a flat file with multiple kinds of different records, so splitting this record into child-records is not a viable solution.
I was able to validate the input from the top of your post with the following, hopefully it gets you ont he right track:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://BizTalk_Server_Project2.FlatFileSchema2" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://BizTalk_Server_Project2.FlatFileSchema2" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
<b:schemaInfo standard="Flat File" codepage="65001" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" root_reference="FILE" />
</xs:appinfo>
</xs:annotation>
<xs:element name="FILE">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="positional" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
<xs:element name="FILE_Child1" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_offset="0" pos_length="6" sequence_number="1" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="FILE_Child2" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_offset="0" pos_length="5" sequence_number="2" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element maxOccurs="unbounded" name="FILE_Child3">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="positional" sequence_number="3" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
</xs:appinfo>
</xs:annotation>
<xs:element name="FILE_Child3_Child1" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_offset="0" pos_length="6" sequence_number="1" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="FILE_Child3_Child2" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo justification="left" pos_offset="0" pos_length="6" sequence_number="2" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

BizTalk flat file nested xml

BizTalk flat file schema with nested nodes is giving me some trouble. What is happening is that the child record delimiter is showing up as data in the last field. I followed the recipe from this old blog post.
Managing Flat Files in BizTalk 2004
Here is the input and schema are here.
https://bitbucket.org/kirk98445/stuff/src/90becbaa638b1bc42555cf84f2a1a4cb4f3cd3fc?at=master
Result is that the xml looks fine for the most part except for the crlf in the user and ponumber fields.
<Orders xmlns="http://KS.Biztalk.EDI.Common.Amtech.ASN.FlatFileSchema1"><Header><user>USER_1234
</user></Header><Order><OrderHeader><ponumber>PO_001
</ponumber></OrderHeader><LineItems><LineItem><item>Item32 33</item></LineItem><LineItem><item>Item63 45</item></LineItem></LineItems></Order><Order><OrderHeader><ponumber>PO_002
</ponumber></OrderHeader><LineItems><LineItem><item>Item454 12</item></LineItem></LineItems></Order></Orders>
There are issues with your schema.
Record "Orders" - The Child Delimiter Type property is not set for a delimited record.
Record "Order" - The Child Delimiter Type property is not set for a delimited record.
Usually with this sort of flat file I would create one schema for the header, and then one for the Order & Order Lines. Then in the flat file dissembler define set the Header schema and the Document schema to the above two.
This way it will de-batch you will get a message for each purchase order in the file.
But if you want it in a single schema, try this schema that uses a Sequence Group node.
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://KS.Biztalk.EDI.Common.Amtech.ASN.FlatFileSchema1" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" elementFormDefault="qualified" targetNamespace="http://KS.Biztalk.EDI.Common.Amtech.ASN.FlatFileSchema1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<b:schemaInfo standard="Flat File" root_reference="Orders" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="true" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" child_delimiter_type="hex" default_child_delimiter="0x0D 0x0A" default_child_order="postfix" />
<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Orders">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" child_order="postfix" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element minOccurs="1" maxOccurs="1" name="Header">
<xs:annotation>
<xs:appinfo>
<b:recordInfo sequence_number="1" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="HEADER" child_delimiter_type="hex" child_delimiter="0x09" child_order="prefix" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="user" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:sequence maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="2" />
</xs:appinfo>
</xs:annotation>
<xs:element name="OrderHeader">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="PURCHASE" child_order="prefix" child_delimiter_type="hex" child_delimiter="0x09" sequence_number="1" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="ponumber" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="unbounded" name="LineItem">
<xs:annotation>
<xs:appinfo>
<b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="LINEITEM" child_delimiter_type="hex" child_delimiter="0x09" child_order="prefix" sequence_number="2" />
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:annotation>
<xs:appinfo>
<b:groupInfo sequence_number="0" />
</xs:appinfo>
</xs:annotation>
<xs:element name="item" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="1" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Qty" type="xs:string">
<xs:annotation>
<xs:appinfo>
<b:fieldInfo sequence_number="2" justification="left" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Resources