如何为具有重复序列的记录定义Flat文件架构?

时间:2015-04-01 09:02:09

标签: xsd biztalk flat-file

我有一个位置平面文件,其中包含重复序列的记录,如下所示;

TOKEN NAME LABEL VALUE LABEL VALUE LABEL VALUE LABEL VALUE ..

TOKEN标识记录的类型,名称是名称值,LABEL(10个位置)和VALUE(50个位置)对可以重复不固定的次数(1 .. *)。

我已经定义了一个平面文件架构,如下所示;它包含一个(1 .. *),带有LABEL和一个带有正确位置数据的值:

repeating sequence schema

LABEL和VALUE都有 minOccurs maxOccurs 为1。

我遇到的问题是BizTalk没有接缝能够处理这种情况。当我为此模式生成(本机)实例时,我得到以下输出:

TOKEN NAME        LABEL     VALUE                                             

(它只生成一个LABEL VALUE实例)。

当我尝试读取多次出现LABEL VALUE对(5)的文件时,它会给我以下XML:

<FILE xmlns="http://schemas.demo/2015/01">
    <RepeatingRecord xmlns="">
        <NAME>NAME</NAME>
        <LABEL>LABEL</LABEL>
        <LABEL>VALUE</LABEL>
        <LABEL>LABEL</LABEL>
        <LABEL>VALUE</LABEL>
        <LABEL>LABEL</LABEL>
        <LABEL>VALUE</LABEL>
        <LABEL>LABEL</LABEL>
        <LABEL>VALUE</LABEL>
        <LABEL>LABEL</LABEL>
        <LABEL>VALUE</LABEL>
    </RepeatingRecord>
</FILE>

所以我只获得LABEL标签,但没有VALUE标签。 VALUE部分的内容错误地放在LABEL标记中。

我希望以下XML:

<FILE xmlns="http://schemas.demo/2015/01">
    <RepeatingRecord xmlns="">
        <NAME>NAME</NAME>
        <LABEL>LABEL</LABEL>
        <VALUE>VALUE</VALUE>
        <LABEL>LABEL</LABEL>
        <VALUE>VALUE</VALUE>
        <LABEL>LABEL</LABEL>
        <VALUE>VALUE</VALUE>
        <LABEL>LABEL</LABEL>
        <VALUE>VALUE</VALUE>
        <LABEL>LABEL</LABEL>
        <VALUE>VALUE</VALUE>
    </RepeatingRecord>
</FILE>

如何在记录中定义具有重复序列的平面文件架构?

我目前有以下架构:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://schemas.goudse.nl/irma/adapter/2015/01" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://schemas.goudse.nl/irma/adapter/2015/01" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <b:schemaInfo standard="Flat File" root_reference="FILE" default_pad_char="0x20" pad_char_type="hex" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="true" generate_empty_nodes="false" allow_early_termination="true" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" document_type="ASFBatchFlatFileSchema" version="2015.01" schema_type="document" default_child_order="postfix" child_delimiter_type="hex" default_child_delimiter="0x0D 0x0A" />
      <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="FILE">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo structure="delimited" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" sequence_number="1" child_order="default" notes="Een compleet bestand" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence minOccurs="1" maxOccurs="1">
        <xs:annotation>
          <xs:appinfo>
            <b:groupInfo sequence_number="0" />
          </xs:appinfo>
        </xs:annotation>
        <xs:element minOccurs="1" maxOccurs="unbounded" name="RepeatingRecord">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="positional" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" tag_name="TOKEN " notes="Data behorende bij de schadebrief" 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="NAME" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="1" pos_length="12" pos_offset="6" pad_char_type="hex" pad_char="0x20" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:sequence minOccurs="1" maxOccurs="unbounded">
                <xs:annotation>
                  <xs:appinfo>
                    <b:groupInfo sequence_number="2" />
                  </xs:appinfo>
                </xs:annotation>
                <xs:element minOccurs="1" maxOccurs="1" name="LABEL" type="xs:string">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:fieldInfo justification="left" pos_length="10" pad_char_type="hex" pad_char="0x20" sequence_number="1" />
                    </xs:appinfo>
                  </xs:annotation>
                </xs:element>
                <xs:element minOccurs="1" maxOccurs="1" name="VALUE" type="xs:string">
                  <xs:annotation>
                    <xs:appinfo>
                      <b:fieldInfo justification="left" pos_length="50" pad_char_type="hex" pad_char="0x20" sequence_number="2" />
                    </xs:appinfo>
                  </xs:annotation>
                </xs:element>
              </xs:sequence>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

和以下测试数据文件(为了清晰起见,用句点替换了空格,模式定义了填充空格)。

TOKEN.NAME........LABEL.....VALUE.............................................LABEL.....VALUE.............................................LABEL.....VALUE.............................................LABEL.....VALUE.............................................LABEL.....VALUE.............................................

更新

我在这个问题中没有提到的(为了简单起见)是这个记录用在具有多种不同记录的平面文件中,因此将此记录拆分为子记录并不是一个可行的解决方案。 p>

1 个答案:

答案 0 :(得分:2)

我能够通过以下内容验证您帖子顶部的输入,希望它能让您顺利通过:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://BizTalk_Server_Project2.FlatFileSchema2" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://BizTalk_Server_Project2.FlatFileSchema2" 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="FILE" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="FILE">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo structure="positional" 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 name="FILE_Child1" type="xs:string">
          <xs:annotation>
            <xs:appinfo>
              <b:fieldInfo justification="left" pos_offset="0" pos_length="6" sequence_number="1" />
            </xs:appinfo>
          </xs:annotation>
        </xs:element>
        <xs:element name="FILE_Child2" type="xs:string">
          <xs:annotation>
            <xs:appinfo>
              <b:fieldInfo justification="left" pos_offset="0" pos_length="5" sequence_number="2" />
            </xs:appinfo>
          </xs:annotation>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="FILE_Child3">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="positional" sequence_number="3" 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 name="FILE_Child3_Child1" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" pos_offset="0" pos_length="6" sequence_number="1" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="FILE_Child3_Child2" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" pos_offset="0" pos_length="6" sequence_number="2" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>