Jay
Jay

Reputation: 14471

Understanding BizTalk flat file schemas

I'm trying to modify the schema generated by the BizTalk flat file wizard. It's very complex and I'd rather not spend days getting the wizard to make something workable again.

The input is a complex file consisting of carriage return/line feed delimited records. There's currently a single line with a tag at the front to identify it. They would like to add the ability to accept the current line or another similar line.

I need any number of either of two lines in any order.

I created a definition for the second line after the first. I then surrounded the two line definitions with a Choice node. The choice node is set to minOccurs="0" maxOccurs="unbounded". I assumed this would give me any number of blocks of either line:

<xs:choice minOccurs="0" maxOccurs="unbounded">
  <xs:annotation>
    <xs:appinfo>
      <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="2" />
    </xs:appinfo>
  </xs:annotation>

  <xs:element name="GROS">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo structure="positional" tag_name="GROS" tag_offset="0" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
      </xs:appinfo>
    </xs:annotation>
    ...
  </xs:element>

  <xs:element name="GRSD">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo structure="positional" tag_name="GRSD" tag_offset="0" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
      </xs:appinfo>
    </xs:annotation>
    ...
  </xs:element>

</xs:choice>

It fails on the third line:

GROS ...
GRSD ...
GRSD ...

Any suggestions? My brain hurts.

Upvotes: 0

Views: 1126

Answers (2)

Jay
Jay

Reputation: 14471

I was finally able to get it to work by going at it sideways. I modified the existing node and replaced the record identifying tag with a 'TagIdentifier' string field. That got around the requirement for multiple types of nodes in different combinations. I modified the map to test the content of the string field to determine which type of record was received.

This will only work because the two records are otherwise identical.

Upvotes: 1

Dijkgraaf
Dijkgraaf

Reputation: 11527

Given a payload that looks like

GROS1234567890 CR LF
GRSD1234567890 CR LF
GRSD1234567890 CR LF

The following schema will happily parse that by tag and then by positional

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.FlatFileSchema40516683" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.FlatFileSchema40516683" 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>
        <recordInfo sequence_number="1" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
      </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:choice minOccurs="0" maxOccurs="unbounded">
          <xs:annotation>
            <xs:appinfo>
              <groupInfo sequence_number="1" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
            </xs:appinfo>
          </xs:annotation>
          <xs:element name="GROS">
            <xs:annotation>
              <xs:appinfo>
                <recordInfo sequence_number="1" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="GROS" child_order="postfix" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
              </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="Fields">
                  <xs:annotation>
                    <xs:appinfo>
                      <recordInfo sequence_number="1" structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
                    </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="Field" type="xs:string">
                        <xs:annotation>
                          <xs:appinfo>
                            <fieldInfo sequence_number="1" justification="left" pos_length="5" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
                          </xs:appinfo>
                        </xs:annotation>
                      </xs:element>
                      <xs:element name="Field2" type="xs:string">
                        <xs:annotation>
                          <xs:appinfo>
                            <fieldInfo sequence_number="2" justification="left" pos_length="5" 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:element name="GRSD">
            <xs:annotation>
              <xs:appinfo>
                <recordInfo sequence_number="2" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_delimiter_type="hex" child_delimiter="0x0D 0x0A" child_order="postfix" tag_name="GRSD" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
              </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="Fields">
                  <xs:annotation>
                    <xs:appinfo>
                      <recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
                    </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="Field" type="xs:string">
                        <xs:annotation>
                          <xs:appinfo>
                            <fieldInfo sequence_number="1" justification="left" pos_length="5" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
                          </xs:appinfo>
                        </xs:annotation>
                      </xs:element>
                      <xs:element name="Field2" type="xs:string">
                        <xs:annotation>
                          <xs:appinfo>
                            <fieldInfo sequence_number="2" justification="left" pos_length="5" 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:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Output

<Root xmlns="http://Scratch.FlatFileSchema40516683">
    <GROS xmlns="">
        <Fields>
            <Field>12345</Field>
            <Field2>67890</Field2>
        </Fields>
    </GROS>
    <GRSD xmlns="">
        <Fields>
            <Field>12345</Field>
            <Field2>67890</Field2>
        </Fields>
    </GRSD>
    <GRSD xmlns="">
        <Fields>
            <Field>12345</Field>
            <Field2>67890</Field2>
        </Fields>
    </GRSD>
</Root>

The main difference is that I have put a Fields record (positional) below the tagged record (which is delimited by CR LF).

Note, this will only work if all records finish with a CR LF as the delimiter is defined as Postfix (expect the delimiter after it).

Upvotes: 1

Related Questions