【问题标题】:Positional flat file with nested records具有嵌套记录的位置平面文件
【发布时间】:2019-02-09 04:36:01
【问题描述】:

请好心人给我建议或帮助我解决这个平面文件吗?我不知道如何实现我想要的。

正如您在下面看到的,有一些字段可以用作标签标识符。

我们有“S”表示开始标签,“I”表示客户信息,“F”表示发票详细信息,“N”表示注释部分,最后是“E”表示结束部分。正如您所看到的,也有重复的记录,这种嵌套和位置记录的使用给我带来了麻烦。 因此,每个 F 部分(客户)都有自己的一套重复发票和附注。

我确实尝试了这个美妙的post 的提示,但不幸的是,在这个问题中不存在嵌套。

奇怪的是,如果我不考虑位置记录,我可以设法得到我想要的。如果我只是将整个数据放入一个字段(即整个 F 没有定位),我可以得到正确的结构,其中包括重复。但它们是定位的,I、F 和 N,我所有的努力总是导致错误,要么说明它正在寻找标签标识符字母,要么它正在寻找回车和行尾。任何帮助都将不胜感激,因为我已经为此苦苦挣扎了一段时间。

示例文件:

S                                                                                                                                                                                                       
I02710242Company name 01               Postboks 123 Sum                                            010223 14 15 50 54                            9597598396200468                             NO                                                                                                                                                                                      N                                                          
F141220178065428         00000102700-13012018000000080654288                                                                                                                  
NINK       !!!!!!!!!!!                                                                                                                                                                                                               
F141220178065429         00000197200-13012018000000080654296                                                                                                                  
NINK       !!!!!!!!!!!                                                                                                                                                                                                               
I02710242Company name 02               Postboks 234 Seum                                           010223 14 16 50 54                            9597598396200468                             NO                                                                                                                                                                                      N                                                          
F050120185794526         00003686250+04022018000000057945263                                                                                                                  
NINK       !!!!!!!!!!!                                                                                                                                                                                                               
F141220178065428         00000102700-13012018000000080654288                                                                                                                  
NINK       !!!!!!!!!!!                                                                                                                                                                                                               
F141220178065429         00000197200-13012018000000080654296                                                                                                                  
NINK       !!!!!!!!!!!                                                                                                                                                                                                               
E000000420000005000030679668+

所以我想我想要实现的(除非你们有更好的设置)是一个看起来像这样的架构:

S
---I
     -F
     -N
     -F
     -N

  -I 
     -F
     -N
     -F
     -N
E

【问题讨论】:

  • 您在使用平面文件向导吗?
  • 嗨。是的。我已经尝试了模式的向导和手动创建。不幸的是,我无法让它工作。我更喜欢模式向导和手动处理的组合,这样我就可以彻底了解该过程以及它的内容和方法。

标签: nested biztalk flat-file


【解决方案1】:

诀窍是,在向导的一个步骤中,您选择整个重复组 (I...N) 并设置一个重复元素的组。

然后,向导将深入到 I...N 并让您定义子记录,这些子记录也可以是重复的组或带字段的记录。

多次运行向导以使结构正确并没有错。我们都做过……很多次。

【讨论】:

    【解决方案2】:

    我为您准备了一个示例,这将通过您的示例消息进行验证。我在没有向导的情况下做了这个。尽管向导是了解某些事情的一个很好的起点,但复杂的嵌套应该手动尝试。

    需要注意的几点:

    • 您的子订单是每个重复 record 的中缀。
    • 您没有非重复订单的子订单,而是指定为positional
    • 如果重复,则分隔符是换行符。这意味着在每个重复的 record 上,您都指定了该分隔符,或者您在 <Schema> 级别指定了默认分隔符。

    我认为您的问题部分在于识别模式,正如您在我的示例中看到的那样,模式是不同的;在I 行之后,有FN 行的重复模式,我将其封装在名为Repeatingchild 的记录中。

    你仍然可以让你的模式工作;

    • 通过删除Repeatingchild 记录并将所有元素放在Repeating 记录中来编辑我的示例。
    • <Schema>级别将Parser Optimization设置为Complexity,如果不这样做,I记录就会出现问题。

    仍然缺少的是每个字段的确切位置映射,但我已经用我放置的 Irecord_part1Irecord_part2 证明了位置性。我接下来要做的仍然是对每一行单独使用向导来制作所有行元素。因此,拆分每一行并在每种行类型上运行向导。

    为了让它更漂亮,你可以让单个模式代表header and the trailer。所以我猜S 记录将是标题,E 记录将是预告片。

     <?xml version="1.0" encoding="utf-16"?>
        <xs:schema xmlns="StackOverflow.FlatFileSchema1" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="StackOverflow.FlatFileSchema1" 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="true" 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_delimiter_type="hex" child_order="infix" child_delimiter="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="SRecord">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" tag_name="S" />
                    </xs:appinfo>
                  </xs:annotation>
                  <xs:complexType>
                    <xs:sequence>
                      <xs:annotation>
                        <xs:appinfo>
                          <b:groupInfo sequence_number="0" />
                        </xs:appinfo>
                      </xs:annotation>
                      <xs:element name="Srecord" type="xs:string">
                        <xs:annotation>
                          <xs:appinfo>
                            <b:fieldInfo justification="left" sequence_number="1" pos_length="200" />
                          </xs:appinfo>
                        </xs:annotation>
                      </xs:element>
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
                <xs:element minOccurs="0" maxOccurs="unbounded" name="Repeating">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:recordInfo sequence_number="2" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_delimiter_type="hex" child_delimiter="0x0A" child_order="infix" repeating_delimiter_type="hex" repeating_delimiter="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="0" maxOccurs="unbounded" name="IRecord">
                        <xs:annotation>
                          <xs:appinfo>
                            <b:recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" tag_name="I" />
                          </xs:appinfo>
                        </xs:annotation>
                        <xs:complexType>
                          <xs:sequence>
                            <xs:annotation>
                              <xs:appinfo>
                                <b:groupInfo sequence_number="0" />
                              </xs:appinfo>
                            </xs:annotation>
                            <xs:element name="Irecord_part1" type="xs:string">
                              <xs:annotation>
                                <xs:appinfo>
                                  <b:fieldInfo justification="left" sequence_number="1" pos_length="133" />
                                </xs:appinfo>
                              </xs:annotation>
                            </xs:element>
                            <xs:element name="Irecord_part2" type="xs:string">
                              <xs:annotation>
                                <xs:appinfo>
                                  <b:fieldInfo sequence_number="2" justification="left" pos_length="200" />
                                </xs:appinfo>
                              </xs:annotation>
                            </xs:element>
                          </xs:sequence>
                        </xs:complexType>
                      </xs:element>
                      <xs:element minOccurs="0" maxOccurs="unbounded" name="Repeatingchild">
                        <xs:annotation>
                          <xs:appinfo>
                            <b:recordInfo sequence_number="2" structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" child_delimiter_type="hex" child_delimiter="0x0A" child_order="infix" />
                          </xs:appinfo>
                        </xs:annotation>
                        <xs:complexType>
                          <xs:sequence>
                            <xs:annotation>
                              <xs:appinfo>
                                <b:groupInfo sequence_number="0" />
                              </xs:appinfo>
                            </xs:annotation>
                            <xs:element minOccurs="0" maxOccurs="unbounded" name="FRecord">
                              <xs:annotation>
                                <xs:appinfo>
                                  <b:recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" tag_name="F" />
                                </xs:appinfo>
                              </xs:annotation>
                              <xs:complexType>
                                <xs:sequence>
                                  <xs:annotation>
                                    <xs:appinfo>
                                      <b:groupInfo sequence_number="0" />
                                    </xs:appinfo>
                                  </xs:annotation>
                                  <xs:element name="Frecord" type="xs:string">
                                    <xs:annotation>
                                      <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="1" pos_length="174" />
                                      </xs:appinfo>
                                    </xs:annotation>
                                  </xs:element>
                                </xs:sequence>
                              </xs:complexType>
                            </xs:element>
                            <xs:element minOccurs="0" maxOccurs="unbounded" name="NRecord">
                              <xs:annotation>
                                <xs:appinfo>
                                  <b:recordInfo sequence_number="2" structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="N" />
                                </xs:appinfo>
                              </xs:annotation>
                              <xs:complexType>
                                <xs:sequence>
                                  <xs:annotation>
                                    <xs:appinfo>
                                      <b:groupInfo sequence_number="0" />
                                    </xs:appinfo>
                                  </xs:annotation>
                                  <xs:element name="Nrecord" type="xs:string">
                                    <xs:annotation>
                                      <xs:appinfo>
                                        <b:fieldInfo justification="left" sequence_number="1" pos_length="229" />
                                      </xs:appinfo>
                                    </xs:annotation>
                                  </xs:element>
                                </xs:sequence>
                              </xs:complexType>
                            </xs:element>
                          </xs:sequence>
                        </xs:complexType>
                      </xs:element>
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
                <xs:element name="ERecord">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="E" 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="Erecord" type="xs:string">
                        <xs:annotation>
                          <xs:appinfo>
                            <b:fieldInfo justification="left" sequence_number="1" pos_length="29" />
                          </xs:appinfo>
                        </xs:annotation>
                      </xs:element>
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:schema>
    

    【讨论】:

    • 嗨 r3verse。对于这个明确而具体的建议,我非常感谢。从这个平面文件中可以学到很多东西。根据您的建议,我很难正确设置模式,这是真的。我仍然不明白的一件事是为什么分隔符只是换行符。我使用 Notepad++ 并查看包括 CLRF 在内的所有符号。每个新行都有一个。如果你没有告诉我,我永远不会意识到这一点。为什么只重复行换行?需要详细说明吗?再次感谢!
    • CRLF 也表示其中有换行符 (LF)。您仍然可以使用 CRLF 进行分隔,只需使用正确的十六进制即可。仅使用 LF 确保您涵盖 CRLF 和 LF 类型。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    • 2016-10-09
    • 2016-04-02
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    相关资源
    最近更新 更多