Hi, I have a flat-file similar to the one listed below and my problem is to create a hierarchical Xml structure out of it. The first record is "Group" which has no starting spaces and having 2 fields Name[Ex:G1](30 characters) and Description[G1 Desc](40), underlying are "Parent" records (1 or more) each starting with 5 spaces and having 3 fields ParentID[G1P1](25), Desc[G1P1 Desc](30) and Type[T1](10) and underlying Parent records are "Child" records (0 or more) each starting with 10 spaces and having 3 fields ChildID[G1P2C1](20), Desc[G1P2C1 Desc](30) and Type(10) and underlying Child are "SubChild" records (0 or more) each starting with 15 spaces and having 3 fields SubChildID[G1P2C3SC1](15), Desc[G1P2C3SC1 Desc](30) and Type(10). Flat-file instance: G1 G1 Desc G1P1 G1P1 Desc T1 G1P2 G1P2 Desc T2 G1P2C1 G1P2C1 Desc T2 G1P2C2 G1P2C2 Desc T2 G1P2C3 G1P2C3 Desc T2 G1P2C3SC1 G1P2C3SC1 Desc T2 G1P2C3SC2 G1P2C3SC2 Desc T2 G1P2C3SC3 G1P2C3SC3 Desc T2 G1P2C3SC4 G1P2C3SC4 Desc T2 G1P2C4 G1P2C4 Desc T2 G1P2C4SC1 G1P2C4SC1 Desc T2 G1P2C4SC2 G1P2C4SC2 Desc T2 G1P2C5 G1P2C5 Desc T2 G1P2C6 G1P2C6 Desc T2 G1P2C7 G1P2C7 Desc T2 G1P2C7SC1 G1P2C7SC1 Desc T2 G1P2C7SC2 G1P2C7SC2 Desc T2 G1P2C7SC3 G1P2C7SC3 Desc T2 G1P2C8 G1P2C8 Desc T2 G1P2C9 G1P2C9 Desc T2 G1P3 G1P3 Desc T3 G1P3C1 G1P3C1 Desc T3 G1P3C2 G1P3C2 Desc T3 G1P3C3 G1P3C3 Desc T3 G2 G2 Desc G2P1 G2P1 Desc T2 G2P1C1 G2P1C1 Desc T2 G2P1C2 G2P1C2 Desc T2 G2P1C3 G2P1C3 Desc T2 I was able to build a schema (thanks to Jan) which looks like: <?xml version="1.0" encoding="utf-16"?> <xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" 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" count_positions_by_byte="true" default_pad_char=" " pad_char_type="char" 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" root_reference="Root" codepage="1252" /> </xs:appinfo> </xs:annotation> <xs:element name="Root"> <xs:annotation> <xs:appinfo> <b:recordInfo structure="delimited" 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 minOccurs="0" maxOccurs="unbounded" name="Record"> <xs:annotation> <xs:appinfo> <b:recordInfo sequence_number="1" structure="delimited" 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="Groups"> <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="Group"> <xs:annotation> <xs:appinfo> <b:recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" /> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:attribute name="Name" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="1" justification="left" pos_offset="0" pos_length="30" /> </xs:appinfo> </xs:annotation> </xs:attribute> <xs:attribute name="Description" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="2" justification="left" pos_length="40" /> </xs:appinfo> </xs:annotation> </xs:attribute> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element maxOccurs="unbounded" name="Accounts"> <xs:annotation> <xs:appinfo> <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="true" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" sequence_number="2" child_order="postfix" /> </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="Parent"> <xs:annotation> <xs:appinfo> <recordInfo sequence_number="1" structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name=" " xmlns="http://schemas.microsoft.com/BizTalk/2003" /> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:attribute name="ID" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="1" justification="left" pos_offset="5" pos_length="25" /> </xs:appinfo> </xs:annotation> </xs:attribute> <xs:attribute name="Description" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="2" justification="left" pos_length="30" /> </xs:appinfo> </xs:annotation> </xs:attribute> <xs:attribute name="Type" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="3" justification="left" pos_length="10" /> </xs:appinfo> </xs:annotation> </xs:attribute> </xs:complexType> </xs:element> <xs:element minOccurs="0" maxOccurs="unbounded" name="Child"> <xs:annotation> <xs:appinfo> <recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name=" " xmlns="http://schemas.microsoft.com/BizTalk/2003" sequence_number="2" /> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:attribute name="ID" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="1" justification="left" pos_offset="10" pos_length="20" /> </xs:appinfo> </xs:annotation> </xs:attribute> <xs:attribute name="Description" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="2" justification="left" pos_length="30" /> </xs:appinfo> </xs:annotation> </xs:attribute> <xs:attribute name="Type" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="3" justification="left" pos_length="10" /> </xs:appinfo> </xs:annotation> </xs:attribute> </xs:complexType> </xs:element> <xs:element minOccurs="0" maxOccurs="unbounded" name="SubChild"> <xs:annotation> <xs:appinfo> <b:recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name=" " sequence_number="3" /> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:attribute name="ID" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="1" justification="left" pos_offset="15" pos_length="15" /> </xs:appinfo> </xs:annotation> </xs:attribute> <xs:attribute name="Description" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="2" justification="left" pos_length="30" /> </xs:appinfo> </xs:annotation> </xs:attribute> <xs:attribute name="Type" type="xs:string"> <xs:annotation> <xs:appinfo> <b:fieldInfo sequence_number="3" justification="left" pos_length="10" /> </xs:appinfo> </xs:annotation> </xs:attribute> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> Validate Instance output using the above schema & Xml: <Root> <Record> <Groups> <Group Name="G1" Description="G1 Desc"></Group> </Groups> <Accounts> <Parent ID="G1P1" Description="G1P1 Desc" Type="T1"></Parent> </Accounts> <Accounts> <Parent ID="G1P2" Description="G1P2 Desc" Type="T2"></Parent> <Child ID="G1P2C1" Description="G1P2C1 Desc" Type="T2"></Child> <Child ID="G1P2C2" Description="G1P2C2 Desc" Type="T2"></Child> <Child ID="G1P2C3" Description="G1P2C3 Desc" Type="T2"></Child> <SubChild ID="G1P2C3SC1" Description="G1P2C3SC1 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C3SC2" Description="G1P2C3SC2 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C3SC3" Description="G1P2C3SC3 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C3SC4" Description="G1P2C3SC4 Desc" Type="T2"></SubChild> </Accounts> <Accounts> <Parent ID=" G1P2C4" Description="G1P2C4 Desc" Type="T2"></Parent> <SubChild ID="G1P2C4SC1" Description="G1P2C4SC1 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C4SC2" Description="G1P2C4SC2 Desc" Type="T2"></SubChild> </Accounts> <Accounts> <Parent ID=" G1P2C5" Description="G1P2C5 Desc" Type="T2"></Parent> <Child ID="G1P2C6" Description="G1P2C6 Desc" Type="T2"></Child> <Child ID="G1P2C7" Description="G1P2C7 Desc" Type="T2"></Child> <SubChild ID="G1P2C7SC1" Description="G1P2C7SC1 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C7SC2" Description="G1P2C7SC2 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C7SC3" Description="G1P2C7SC3 Desc" Type="T2"></SubChild> </Accounts> <Accounts> <Parent ID=" G1P2C8" Description="G1P2C8 Desc" Type="T2"></Parent> <Child ID="G1P2C9" Description="G1P2C9 Desc" Type="T2"></Child> </Accounts> <Accounts> <Parent ID="G1P3" Description="G1P3 Desc" Type="T3"></Parent> <Child ID="G1P3C1" Description="G1P3C1 Desc" Type="T3"></Child> <Child ID="G1P3C2" Description="G1P3C2 Desc" Type="T3"></Child> <Child ID="G1P3C3" Description="G1P3C3 Desc" Type="T3"></Child> <SubChild ID="" Description="" Type=""></SubChild> </Accounts> </Record> <Record> <Groups> <Group Name="G2" Description="G2 Desc"></Group> </Groups> <Accounts> <Parent ID="G2P1" Description="G2P1 Desc" Type="T2"></Parent> <Child ID="G2P1C1" Description="G2P1C1 Desc" Type="T2"></Child> <Child ID="G2P1C2" Description="G2P1C2 Desc" Type="T2"></Child> <Child ID="G2P1C3" Description="G2P1C3 Desc" Type="T2"></Child> </Accounts> </Record> </Root> Now the issue is when I validate the attached instance I get everything fine till G1P2C3SC4 SubChild record node but when the parser reaches G1P2C4 Child record it assumes that to be a Parent record and creates a new <Account> record and adds it as a Parent record (may be due to the reason that "Account Group Order Type" is set to "Sequence"??? and I can't use either Choice or All since I need multiple optional records) and everything underlying is screwed up. My Expected Xml: <Root> <Record> <Groups> <Group Name="G1" Description="G1 Desc"></Group> </Groups> <Accounts> <Parent ID="G1P1" Description="G1P1 Desc" Type="T1"></Parent> </Accounts> <Accounts> <Parent ID="G1P2" Description="G1P2 Desc" Type="T2"></Parent> <Child ID="G1P2C1" Description="G1P2C1 Desc" Type="T2"></Child> <Child ID="G1P2C2" Description="G1P2C2 Desc" Type="T2"></Child> <Child ID="G1P2C3" Description="G1P2C3 Desc" Type="T2"></Child> <SubChild ID="G1P2C3SC1" Description="G1P2C3SC1 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C3SC2" Description="G1P2C3SC2 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C3SC3" Description="G1P2C3SC3 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C3SC4" Description="G1P2C3SC4 Desc" Type="T2"></SubChild> <Child ID="G1P2C4" Description="G1P2C4 Desc" Type="T2"></Child> <SubChild ID="G1P2C4SC1" Description="G1P2C4SC1 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C4SC2" Description="G1P2C4SC2 Desc" Type="T2"></SubChild> <Child ID="G1P2C5" Description="G1P2C5 Desc" Type="T2"></Child> <Child ID="G1P2C6" Description="G1P2C6 Desc" Type="T2"></Child> <Child ID="G1P2C7" Description="G1P2C7 Desc" Type="T2"></Child> <SubChild ID="G1P2C7SC1" Description="G1P2C7SC1 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C7SC2" Description="G1P2C7SC2 Desc" Type="T2"></SubChild> <SubChild ID="G1P2C7SC3" Description="G1P2C7SC3 Desc" Type="T2"></SubChild> <Child ID="G1P2C8" Description="G1P2C8 Desc" Type="T2"></Child> <Child ID="G1P2C9" Description="G1P2C9 Desc" Type="T2"></Child> </Accounts> <Accounts> <Parent ID="G1P3" Description="G1P3 Desc" Type="T3"></Parent> <Child ID="G1P3C1" Description="G1P3C1 Desc" Type="T3"></Child> <Child ID="G1P3C2" Description="G1P3C2 Desc" Type="T3"></Child> <Child ID="G1P3C3" Description="G1P3C3 Desc" Type="T3"></Child> <SubChild ID="" Description="" Type=""></SubChild> </Accounts> </Record> <Record> <Groups> <Group Name="G2" Description="G2 Desc"></Group> </Groups> <Accounts> <Parent ID="G2P1" Description="G2P1 Desc" Type="T2"></Parent> <Child ID="G2P1C1" Description="G2P1C1 Desc" Type="T2"></Child> <Child ID="G2P1C2" Description="G2P1C2 Desc" Type="T2"></Child> <Child ID="G2P1C3" Description="G2P1C3 Desc" Type="T2"></Child> </Accounts> </Record> </Root> Appreciate your help in resolving this issue. TIA, Kiran Pabba