Biztalk架构允许分隔文件中的可变列数?

Biztalk架构允许分隔文件中的可变列数?,biztalk,biztalk-mapper,Biztalk,Biztalk Mapper,你好。我有一位客户以平面文件的形式向我们发送订单。该文件实际上并不复杂,但文件之间存在一些不一致 文件的格式如下所示: 1,2,3[CRLF] 1,2,3[CRLF] 围绕该结构创建模式没有问题,但是他们会不时添加一个新列 1,2,3,4[CRLF] 1,2,3,4[CRLF] 不幸的是,他们没有将更改向后级联,因此我们希望同时支持3列和4列格式。这两种格式都可能通过相同的管道,因此我实际上没有创建单独模式/管道的选项。他们总是在行的末尾添加新字段,这样至少在很大程度上是一致的 我能想到的唯一一

你好。我有一位客户以平面文件的形式向我们发送订单。该文件实际上并不复杂,但文件之间存在一些不一致

文件的格式如下所示:

1,2,3[CRLF]
1,2,3[CRLF]

围绕该结构创建模式没有问题,但是他们会不时添加一个新列

1,2,3,4[CRLF]
1,2,3,4[CRLF]

不幸的是,他们没有将更改向后级联,因此我们希望同时支持3列和4列格式。这两种格式都可能通过相同的管道,因此我实际上没有创建单独模式/管道的选项。他们总是在行的末尾添加新字段,这样至少在很大程度上是一致的

我能想到的唯一一件事是创建一个精心设计的“弄清楚哪个模式适用,并相应地路由管道组件”,但在我走这条路之前,我想看看是否有人有一些想法,可以让它使用单个平面文件模式(我尝试将可选列的minOccurs属性设置为0,但效果不佳)


提前感谢您的建议。

一种方法是为您需要支持的不同版本定义一个“外部”模式和导入模式。外部模式将提供一个
选项
块,其中包含对导入版本模式的引用

如果需要添加下一个版本,只需导入一个新的模式并将其添加到
选项

当然,最难的部分是如何确定如何处理不同的版本。也许最简单的方法是为需要处理的每种专用类型创建一个映射。另一方面,您可以扩展“最新和最好的”内部消息类型,并根据消息内容进行决定

外部模式

<!-- language: xml-schema -->

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:ns0="http://ACME.Version_001" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://ACME.Outer" xmlns:ns1="http://ACME.Version_002" targetNamespace="http://ACME.Outer" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:import schemaLocation=".\version_002.xsd" namespace="http://ACME.Version_002" />
    <xs:import schemaLocation=".\version_001.xsd" namespace="http://ACME.Version_001" />
    <xs:annotation>
        <xs:appinfo>
            <b:schemaInfo standard="Flat File" root_reference="Root" />
            <schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
            <b:references>
                <b:reference targetNamespace="http://ACME.Version_001" />
                <b:reference targetNamespace="http://ACME.Version_002" />
            </b:references>
        </xs:appinfo>
    </xs:annotation>
    <xs:element name="Root">
        <xs:annotation>
            <xs:appinfo>
                <b:recordInfo structure="delimited" sequence_number="1" child_delimiter_type="hex" child_order="postfix" child_delimiter="0x0D 0x0A" />
            </xs:appinfo>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:choice minOccurs="1">
                    <xs:element ref="ns0:Version_001">
                        <xs:annotation>
                            <xs:appinfo>
                                <b:recordInfo sequence_number="1" structure="delimited" />
                            </xs:appinfo>
                        </xs:annotation>
                    </xs:element>
                    <xs:element ref="ns1:Version_002">
                        <xs:annotation>
                            <xs:appinfo>
                                <b:recordInfo sequence_number="2" structure="delimited" />
                            </xs:appinfo>
                        </xs:annotation>
                    </xs:element>
                </xs:choice>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

导入的架构“版本001”


导入的架构“版本002”



(为了可读性,省略了一些默认属性)

一种方法是为需要支持的不同版本定义“外部”架构和导入架构。“外部”架构将提供一个
选项
块,其中包含对导入版本架构的引用

如果需要添加下一个版本,只需导入一个新的模式并将其添加到
选项

当然,最难的部分是如何确定如何处理不同的版本。也许最简单的方法是为需要处理的每种专用类型创建一个映射。另一方面,您可以扩展“最新和最好的”内部消息类型,并根据消息内容进行决定

外部模式

<!-- language: xml-schema -->

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:ns0="http://ACME.Version_001" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://ACME.Outer" xmlns:ns1="http://ACME.Version_002" targetNamespace="http://ACME.Outer" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:import schemaLocation=".\version_002.xsd" namespace="http://ACME.Version_002" />
    <xs:import schemaLocation=".\version_001.xsd" namespace="http://ACME.Version_001" />
    <xs:annotation>
        <xs:appinfo>
            <b:schemaInfo standard="Flat File" root_reference="Root" />
            <schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
            <b:references>
                <b:reference targetNamespace="http://ACME.Version_001" />
                <b:reference targetNamespace="http://ACME.Version_002" />
            </b:references>
        </xs:appinfo>
    </xs:annotation>
    <xs:element name="Root">
        <xs:annotation>
            <xs:appinfo>
                <b:recordInfo structure="delimited" sequence_number="1" child_delimiter_type="hex" child_order="postfix" child_delimiter="0x0D 0x0A" />
            </xs:appinfo>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:choice minOccurs="1">
                    <xs:element ref="ns0:Version_001">
                        <xs:annotation>
                            <xs:appinfo>
                                <b:recordInfo sequence_number="1" structure="delimited" />
                            </xs:appinfo>
                        </xs:annotation>
                    </xs:element>
                    <xs:element ref="ns1:Version_002">
                        <xs:annotation>
                            <xs:appinfo>
                                <b:recordInfo sequence_number="2" structure="delimited" />
                            </xs:appinfo>
                        </xs:annotation>
                    </xs:element>
                </xs:choice>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

导入的架构“版本001”


导入的架构“版本002”



(为了可读性,省略了一些默认属性)

是否有任何东西可以在记录前面标识不同类型的记录?如果有,您可以使用标记标识符。是否有任何东西可以在记录前面标识不同类型的记录?如果有,您可以使用标记标识符。感谢“选择”模式听起来像是最好的解决方案。谢谢Filburt,“选择”模式听起来像是最好的解决方案。
<!-- language: xml-schema -->

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://ACME.Version_002" targetNamespace="http://ACME.Version_002" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:annotation>
        <xs:appinfo>
            <b:schemaInfo standard="Flat File" root_reference="Version_002" />
            <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="Version_002">
       <xs:annotation>
           <xs:appinfo>
               <b:recordInfo structure="delimited" child_delimiter_type="char" child_order="infix" rootTypeName="Version_001" child_delimiter="," />
           </xs:appinfo>
       </xs:annotation>
       <xs:complexType>
           <xs:sequence>
               <xs:element name="Col1" type="xs:string" />
               <xs:element name="Col2" type="xs:string" />
               <xs:element name="Col3" type="xs:string" />
               <xs:element name="Col4" type="xs:string" />
           </xs:sequence>
       </xs:complexType>
   </xs:element>
</xs:schema>