Developing a Custom Receive Pipeline with Flat File Disassembler

大憨熊 提交于 2019-12-11 23:19:18

问题


I have a .txt file which is in the similar format as below

1115151651515950000055 00012913702613000000000003000 139C0000007000000
1215151651121510000054 00022913803603000000000009000 000279A0000009000
1315115950000065516515 00032813104643000000000007000 000399B0000003000
121515160003290003290000010000000003000

The first 3 lines are body elements but the number of lines in the body part will be unknown(may occur from 1 to unbounded). There is no tag identifier in body part. The last line in the file is always a trailer.The trailer from the file is to be removed prior to parsing so that only the records need parsed. How can this be done using a Pipeline Component in the Flat File Disassembler.


回答1:


You should not need to remove the trailer. What you need it to define a Flat File Schema where the Body Record can occur unbounded and a separate record for the trailer. You have to set the the delimiters on the Root in the example below, Child Delimiter = 0x0D 0x0A (CR LF), Child Delimiter Type = Hexadecimal, Child Order=Infix, but that may vary and you have to declare the correct delimiter and where the occur. For the above file I assumed that there was no CR LF after the trailer, hence chose Infix (delimiter occurs between) rather than Postfix (delimiter occurs after) if the last line does have a CR LF.

You can then define the Body and Trailer Structure to be either Delimited or Positional.

Update: To not have the trailer in the message to be processed, have a map on the receive port that only maps the Body records and not the trailer.

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch.FlatFile" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch.FlatFile" 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="infix" 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="Body">
          <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="BodyContents" 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="Trailer">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo sequence_number="2" 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="TrailerContents" 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:complexType>
  </xs:element>
</xs:schema>


来源:https://stackoverflow.com/questions/25409866/developing-a-custom-receive-pipeline-with-flat-file-disassembler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!