BizTalk Flat File Schema with optional last child record

325 Views Asked by At

I am trying to create a delimited flat file schema that takes care of the following file format:

"ID","Surname","FirstName"{CR}{LF}
"FINAL","123","abc"{CR}{LF}

The above is just one record. The row beginning with "FINAL" is an optional row.

Multiple records in a file can look like:

"ID","Surname","FirstName"{CR}{LF}
"FINAL","123","abc"{CR}{LF}
"ID","Surname","FirstName"{CR}{LF}
"FINAL","456","def"{CR}{LF}

Or, it can also look like the following:

"ID","Surname","FirstName"{CR}{LF}
"ID","Surname","FirstName"{CR}{LF}
"FINAL","123","abc"{CR}{LF}

The final example above contains one record without the optional "FINAL" row, and continues on with the new record right below it. However in this case I get an error (Reason: Unmatched wrap character " ).

I have noticed that if the file contains a {CR}{LF} in place of the missing optional "FINAL" row like the following:

"ID","Surname","FirstName"{CR}{LF}
{CR}{LF}
"ID","Surname","FirstName"{CR}{LF}
"FINAL","123","abc"{CR}{LF}

it seems to work, however I will be receiving files without any extra {CR}{LF} in place of the missing optional row.

Is there a property in the schema that I need to set to take care of this? MinOccurs for the optional child record is set to 0.

1

There are 1 best solutions below

0
Dijkgraaf On

I would use a Choice Group with Tag Identifier

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.MSDNFF" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.MSDNFF" 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:choice minOccurs="0" maxOccurs="unbounded">
          <xs:annotation>
            <xs:appinfo>
              <b:groupInfo sequence_number="1" />
            </xs:appinfo>
          </xs:annotation>
          <xs:element name="ID">
            <xs:annotation>
              <xs:appinfo>
                <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="&quot;ID&quot;," child_order="infix" child_delimiter_type="char" child_delimiter="," 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="Firstname" type="xs:string">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:fieldInfo sequence_number="1" justification="left" wrap_char_type="char" wrap_char="&quot;" />
                    </xs:appinfo>
                  </xs:annotation>
                </xs:element>
                <xs:element name="Surname" type="xs:string">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:fieldInfo sequence_number="2" justification="left" wrap_char_type="char" wrap_char="&quot;" />
                    </xs:appinfo>
                  </xs:annotation>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
          <xs:element minOccurs="0" name="FINAL">
            <xs:annotation>
              <xs:appinfo>
                <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="&quot;FINAL&quot;," child_order="infix" child_delimiter_type="char" child_delimiter="," 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="Number" type="xs:string">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:fieldInfo justification="left" wrap_char_type="char" wrap_char="&quot;" sequence_number="1" />
                    </xs:appinfo>
                  </xs:annotation>
                </xs:element>
                <xs:element name="Letters" type="xs:string">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:fieldInfo justification="left" wrap_char_type="char" wrap_char="&quot;" sequence_number="2" />
                    </xs:appinfo>
                  </xs:annotation>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
          <xs:element minOccurs="0" maxOccurs="unbounded" name="Empty">
            <xs:annotation>
              <xs:appinfo>
                <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" 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 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:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>