2017-09-18 66 views
1

我在BizTalk一个更新,我必须从一个CSV文件创建一个XSD的架构:如何为两级分层数据创建平面文件XSD架构?

CSV-file

正如你所看到的,它包括头部和订单。每个订单都有它自己的订单表头 - 与商店的名称并填充Period字段,但空Quantity,Price,CostCurrency字段。每个订单都有几个职位,填补了所有领域,除了Period。每个订单头都有ItemNumber = 0.如何在这种情况下创建正确的平面文件模式?

OrderDate;OrderNumber;ItemNumber;DESCRIPTION_LONG;Quantity;Price;Cost;Period;Currency 
30-04-17;9;0;Shop: McDonalds;;;;2017-04; 
30-04-17;9;1;Double burger;2;5,99;11,98;;USD 
30-04-17;9;2;Coca-Cola;2;2,19;4,38;;USD 
30-04-17;10;0;Shop: Hunting and fishing;;;;2017-04; 
30-04-17;10;1;Fishing rod;2;10,90;21,80;;USD 
30-04-17;10;2;Bait;5;1,00;5,00;;USD 
30-04-17;10;3;Hunting gun;1;999,00;999,00;;USD 

回答

1

您可能能够做到这一点使用标签标识(见https://blogs.msdn.microsoft.com/biztalknotes/2013/02/05/flat-file-schema-creation-with-tag-identifiers-in-the-input-flat-file-repeating-in-a-random-fashion/的例子),但我不是100%肯定这将没有问题的工作,因为标识符(ItemNumber = 0)不该行的开始。我的经验告诉我,平面文件反汇编程序探测在这些情况下的成功有限。

在这种情况下,我对人们的一般建议不是试图在你的平面文件模式中“强制”结构,因为显然你的平面文件结构没有它。我所看到的是每行都有相同的结构/格式。它只是在功能上有所不同。

从这个角度来看,我会选择一个与CSV文件结构相匹配的平面文件模式(一种记录类型的逗号分隔字段,换行符作为行分隔符),然后映射到一个模式使功能更有意义。

+0

事实上,它可以工作,因为项目的行已填充**货币**字段,标题的行 - 没有。当我创建平面文件架构时,BizTalk认为这些行具有不同的字段数。但问题是我的平面文件有一个头文件,这使得您可以制作平面文件Schema的创建。如何在管道转换开始之前删除我的文件的第一行?或者我如何指定模式跳过第一行? – Vitaliy

+0

哦,不。 “不同的字段数”只在创建模式时才起作用。在工作中它显示正确的结果(相同数量的字段) – Vitaliy

3

我认为最好的选择是将您的平面文件解析为XML,而不要试图强制最终结构,正如Pieter在回答之前所说的那样。事情是这样的:

<Root xmlns="http://BizTalkMassCopy.FlatFileSchema3"> 
    <Header xmlns=""> 
    <HeaderOrderDate>OrderDate</HeaderOrderDate> 
    <HeaderOrderNumber>OrderNumber</HeaderOrderNumber> 
    <HeaderItemNumber>ItemNumber</HeaderItemNumber> 
    <HeaderDescription>DESCRIPTION_LONG</HeaderDescription> 
    <HeaderQuantity>Quantity</HeaderQuantity> 
    <HeaderPrice>Price</HeaderPrice> 
    <HeaderCost>Cost</HeaderCost> 
    <HeaderPeriod>Period</HeaderPeriod> 
    <HeaderCurrency>Currency</HeaderCurrency> 
    </Header> 
    <OrderItem xmlns=""> 
    <OrderDate>30-04-17</OrderDate> 
    <OrderNumber>9</OrderNumber> 
    <ItemNumber>0</ItemNumber> 
    <Description>Shop: McDonalds</Description> 
    <Quantity></Quantity> 
    <Price></Price> 
    <Cost></Cost> 
    <Period>2017-04</Period> 
    <Currency></Currency> 
    </OrderItem> 
    <OrderItem xmlns=""> 
    <OrderDate>30-04-17</OrderDate> 
    <OrderNumber>9</OrderNumber> 
    <ItemNumber>1</ItemNumber> 
    <Description>Double burger</Description> 
    <Quantity>2</Quantity> 
    <Price>5,99</Price> 
    <Cost>11,98</Cost> 
    <Period></Period> 
    <Currency>USD</Currency> 
    </OrderItem> 
    <OrderItem xmlns=""> 
    <OrderDate>30-04-17</OrderDate> 
    <OrderNumber>9</OrderNumber> 
    <ItemNumber>2</ItemNumber> 
    <Description>Coca-Cola</Description> 
    <Quantity>2</Quantity> 
    <Price>2,19</Price> 
    <Cost>4,38</Cost> 
    <Period></Period> 
    <Currency>USD</Currency> 
    </OrderItem> 
    <OrderItem xmlns=""> 
    <OrderDate>30-04-17</OrderDate> 
    <OrderNumber>10</OrderNumber> 
    <ItemNumber>0</ItemNumber> 
    <Description>Shop: Hunting and fishing</Description> 
    <Quantity></Quantity> 
    <Price></Price> 
    <Cost></Cost> 
    <Period>2017-04</Period> 
    <Currency></Currency> 
    </OrderItem> 
    <OrderItem xmlns=""> 
    <OrderDate>30-04-17</OrderDate> 
    <OrderNumber>10</OrderNumber> 
    <ItemNumber>1</ItemNumber> 
    <Description>Fishing rod</Description> 
    <Quantity>2</Quantity> 
    <Price>10,90</Price> 
    <Cost>21,80</Cost> 
    <Period></Period> 
    <Currency>USD</Currency> 
    </OrderItem> 
    <OrderItem xmlns=""> 
    <OrderDate>30-04-17</OrderDate> 
    <OrderNumber>10</OrderNumber> 
    <ItemNumber>2</ItemNumber> 
    <Description>Bait</Description> 
    <Quantity>5</Quantity> 
    <Price>1,00</Price> 
    <Cost>5,00</Cost> 
    <Period></Period> 
    <Currency>USD</Currency> 
    </OrderItem> 
    <OrderItem xmlns=""> 
    <OrderDate>30-04-17</OrderDate> 
    <OrderNumber>10</OrderNumber> 
    <ItemNumber>3</ItemNumber> 
    <Description>Hunting gun</Description> 
    <Quantity>1</Quantity> 
    <Price>999,00</Price> 
    <Cost>999,00</Cost> 
    <Period></Period> 
    <Currency>USD</Currency> 
    </OrderItem> 
</Root> 

配有一台模式与此类似:

<?xml version="1.0" encoding="utf-16"?> 
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://BizTalkMassCopy.FlatFileSchema3" targetNamespace="http://BizTalkMassCopy.FlatFileSchema3" 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> 
     <b:recordInfo structure="delimited" child_delimiter_type="hex" child_delimiter="0xD 0xA" child_order="infix" 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="Header"> 
      <xs:annotation> 
      <xs:appinfo> 
       <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter=";" child_order="infix" 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="HeaderOrderDate" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="1" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="HeaderOrderNumber" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="2" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="HeaderItemNumber" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="3" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="HeaderDescription" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="4" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="HeaderQuantity" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="5" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="HeaderPrice" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="6" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="HeaderCost" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="7" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="HeaderPeriod" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="8" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="HeaderCurrency" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="9" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     <xs:element maxOccurs="unbounded" name="OrderItem"> 
      <xs:annotation> 
      <xs:appinfo> 
       <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter=";" child_order="infix" sequence_number="2" 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="OrderDate" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="1" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="OrderNumber" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="2" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="ItemNumber" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="3" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="Description" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="4" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="Quantity" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="5" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="Price" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="6" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="Cost" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="7" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="Period" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <b:fieldInfo justification="left" sequence_number="8" /> 
        </xs:appinfo> 
       </xs:annotation> 
       </xs:element> 
       <xs:element name="Currency" type="xs:string"> 
       <xs:annotation> 
        <xs:appinfo> 
        <fieldInfo sequence_number="9" justification="left" 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:schema> 

然后用一个图来获得最终结果,分组机制,如Grouping in Biztalk Map Based on Multiple Elements

+0

结果格式是正确的,但包含格式与我的完全不同。我在BizTalk中更新,并且我在转换中不够强大 – Vitaliy

1

我的解决方案,

  1. 创建用于解析平面文件的源模式。

    enter image description here

  2. 的分组结果

    enter image description here

  3. 创建目标架构创建地图组源架构。

enter image description here

  • 添加此联XSLT脚本到地图
  • 对于第一脚本functoid的

    <xsl:key name="groups" match="Order" use="OrderNumber"/> 
    

    对于第二剧本functoid

    <xsl:for-each select="Order[generate-id(.)=generate-id(key('groups',OrderNumber))]"> 
        <xsl:sort select="OrderNumber" order="ascending"/> 
         <xsl:choose> 
         <xsl:when test="OrderDate != 'OrderDate'"> 
          <Order> 
           <OrderDate><xsl:value-of select="OrderDate/text()" /></OrderDate> 
           <OrderNumber><xsl:value-of select="OrderNumber/text()" /></OrderNumber> 
           <Description><xsl:value-of select="Description/text()" /></Description> 
           <Period><xsl:value-of select="Period/text()" /></Period> 
           <Items> 
            <xsl:for-each select="key('groups',OrderNumber)"> 
            <xsl:choose> 
             <xsl:when test="ItemNumber > '0'"> 
              <Item> 
               <ItemNumber><xsl:value-of select="ItemNumber" /></ItemNumber> 
               <Quantity><xsl:value-of select="Quantity" /></Quantity> 
               <Price><xsl:value-of select="Price" /></Price> 
               <Cost><xsl:value-of select="Cost" /></Cost> 
               <Currency><xsl:value-of select="Currency" /></Currency> 
              </Item> 
             </xsl:when> 
            </xsl:choose> 
            </xsl:for-each> 
           </Items> 
          </Order> 
         </xsl:when> 
         </xsl:choose> 
    </xsl:for-each> 
    
    1. 测试您的地图并获取此输出。
    <ns0:Orders xmlns:ns0="http://BizTalkServerTestProject.FlatFileSchema6"> 
        <Order> 
        <OrderDate>30-04-17</OrderDate> 
        <OrderNumber>10</OrderNumber> 
        <Description>Shop: Hunting and fishing</Description> 
        <Period>2017-04</Period> 
        <Items> 
         <Item> 
         <ItemNumber>1</ItemNumber> 
         <Quantity>2</Quantity> 
         <Price>10,90</Price> 
         <Cost>21,80</Cost> 
         <Currency>USD</Currency> 
         </Item> 
         <Item> 
         <ItemNumber>2</ItemNumber> 
         <Quantity>5</Quantity> 
         <Price>1,00</Price> 
         <Cost>5,00</Cost> 
         <Currency>USD</Currency> 
         </Item> 
         <Item> 
         <ItemNumber>3</ItemNumber> 
         <Quantity>1</Quantity> 
         <Price>999,00</Price> 
         <Cost>999,00</Cost> 
         <Currency>USD</Currency> 
         </Item> 
        </Items> 
        </Order> 
        <Order> 
        <OrderDate>30-04-17</OrderDate> 
        <OrderNumber>9</OrderNumber> 
        <Description>Shop: McDonalds</Description> 
        <Period>2017-04</Period> 
        <Items> 
         <Item> 
         <ItemNumber>1</ItemNumber> 
         <Quantity>2</Quantity> 
         <Price>5,99</Price> 
         <Cost>11,98</Cost> 
         <Currency>USD</Currency> 
         </Item> 
         <Item> 
         <ItemNumber>2</ItemNumber> 
         <Quantity>2</Quantity> 
         <Price>2,19</Price> 
         <Cost>4,38</Cost> 
         <Currency>USD</Currency> 
         </Item> 
        </Items> 
        </Order> 
    </ns0:Orders> 
    

    您可以找到模式的完整的源代码,并通过此网址地图。 http://blog.sarslan.com/group-source-schema-in-a-map/

    +0

    看起来不错,但是在重建解决方案期间,您已经在平面文件架构中忘记了[header](https://i.stack.imgur.com/4h025.png)。另外我得到一个错误:'连接到目标节点'Order'的Scripting functoid在'Xslt Call-Template'定义中有一个错误:'xslt根目录没有xsl:template节点'' – Vitaliy

    +0

    你说得对,我完全忘记了标题行,我在XSLT脚本上对它进行了修改。我没有得到这个例外。比较,你可以从http://blog.sarslan.com/wp-content/uploads/2017/09/BizTalkServerTestProject.rar下载解决方案文件.rar –