Biztalk 2010:用大量同名元素映射 xsd [英] Biztalk 2010: mapping an xsd with a lot of elements with the same name

查看:10
本文介绍了Biztalk 2010:用大量同名元素映射 xsd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Bitzalk 2010 中,我应该从输入映射到具有以下结构的 XML:

In Bitzalk 2010 I should map from an input to an XML with the following structure:

<REQUEST>
  <PROGRAM name="PROGRAM123">
    <INPUT>
      <INSTRUCT name="INSTR1">
         <FIELD name="FIELD11">VALUE1</FIELD>
         <FIELD name="FIELD12">VALUE2</FIELD>
         <FIELD name="FIELD13">VALUE3</FIELD>
       </INSTRUCT>
       <INSTRUCT name="INSTR2">
         <FIELD name="FIELD21">VALUE4</FIELD>
         <FIELD name="FIELD22">VALUE5</FIELD>
         <FIELD name="FIELD23">VALUE6</FIELD>
         <FIELD name="FIELD24">VALUE7</FIELD>
       </INSTRUCT>
       <INSTRUCT name="INSTR2">
         <FIELD name="FIELD21">VALUE8</FIELD>
         <FIELD name="FIELD22">VALUE9</FIELD>
         <FIELD name="FIELD23">VALUE10</FIELD>
         <FIELD name="FIELD24">VALUE11</FIELD>
       </INSTRUCT>
     </INPUT>
   </PROGRAM>
</REQUEST>

生成的 XSD 是这样的:

The generated XSD was like this:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="REQUEST" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="REQUEST" msdata:IsDataSet="true" msdata:Locale="en-US">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="PROGRAM">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="INPUT" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="INSTRUCT" minOccurs="0" maxOccurs="unbounded">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="FIELD" nillable="true" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType>
                              <xs:simpleContent msdata:ColumnName="FIELD_Text" msdata:Ordinal="1">
                                <xs:extension base="xs:string">
                                  <xs:attribute name="name" type="xs:string" />
                                </xs:extension>
                              </xs:simpleContent>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                        <xs:attribute name="name" type="xs:string" />
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>    
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" />
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

生成的结构只是一般"的结构.我将不得不使用表循环functoid在Biztalk中映射它.我从这个解决方案中得到了信息:http://hestia.typepad.com/flatlander/2007/01/mapping_fixed_e.html但这对我来说似乎很麻烦(我有 40 个字段和一些常量值).

The generated structure was just "general" and I would have to use the table looping functoid to map it in Biztalk. I have got the information from this solution: http://hestia.typepad.com/flatlander/2007/01/mapping_fixed_e.html But this seems very cumbersome for me (I have got 40 fields with some constant values).

另一种可能性是使用 XSLT.但我没有任何经验,我更愿意直接在 Biztalk 中映射它(没有 XSLT)

Another possibility would be to use XSLT. But I don't have got any experience with it and I would prefer to map it directly in Biztalk (without XSLT)

是否有可能创建 XSD 方案,所以我将在地图编辑器中拥有所有字段并在其中创建映射(不使用表循环 functoid).

Is there the possibility of creating an XSD scheme, so I would have all the fields in the map editor and create the mapping in there (without using the table looping functoid).

任何想法/评论都将不胜感激(即使答案是:使用 XSLT")

Any ideas / comments would be appreciated (even if the answer is: "use XSLT")

推荐答案

无论如何,我们通常最终都会将 XSLT 用于任何非平凡的地图.

FWIW we generally wind up using XSLT for any non-trivial maps anyway.

无论如何,BizTalk 都会为您创建 XSLT :)

And BizTalk creates the XSLT for you anyway :)

所以会推荐:

  • 尽可能使用 BizTalk 映射器(REQUEST、PROGRAM、INPUT 和 INSTRUCT 似乎是可映射的)
  • 编译您的项目
  • 在 Visual Studio 的解决方案资源管理器中单击您的 .btm 文件,然后选择顶部的显示所有文件".您现在应该会看到一个隐藏文件 SameFileName.btm.cs.在此文件中是 BizTalk 生成的 XSLT.复制此 XSLT,并将其粘贴到一个新文件中 - 将其另存为 .xslt.您需要将双引号替换为单引号.
  • 再次打开原始 .btm(地图).单击模式之间的地图灰色区域(网格属性).在自定义 XSLT 路径"属性中,选择新创建的 .XSLT 文件.
  • Do as best as you can with the BizTalk mapper (it seems REQUEST, PROGRAM, INPUT and INSTRUCT are mappable)
  • Compile your project
  • Click on your .btm file in the Solution Explorer in Visual Studio, and then select "Show all Files" at the top. You should now see a hidden file SameFileName.btm.cs. In this file is the XSLT that BizTalk generates. Copy this XSLT, and paste it into a new file - save this as .xslt. You'll need to replace the double quotes with single quotes.
  • Open the original .btm (map) again. Click on the map grey area between the schemas (Grid Properties). In the 'Custom XSLT Path' Property, select your newly created .XSLT file.

BizTalk 的映射器为您提供了 XSLT 的先机,您应该能够很容易地掌握基本的 XSLT.一个问题 - 确保记住命名空间别名前缀(通常是 s1)

BizTalk's mapper has given you a headstart on your XSLT, and you should be able to pick up basic XSLT pretty easily. One gotcha - make sure that you remember the namespace alias prefix (usually s1)

请注意,以上内容适用于 BizTalk 2009

Edit : Note that the above is for BizTalk 2009

编辑

作为一个理智的预防措施,在 btm 的可视化地图中,我建议您手动删除灰色映射区域中的所有映射线和 functoid,以防您忘记您现在正在使用自定义 xslt.如果您使用自定义 xslt 测试地图,则映射器会发出提醒,提醒您使用 xslt 文件并忽略可视地图.

As a sanity precaution, in the visual map of the btm, I suggest that you manually delete all the mapping lines and functoids from the grey mapping area, in case you forget that you are now using custom xslt. If you test a map with custom xslt, the mapper does issue a reminder that the xslt file is used and the visual map is ignored.

这篇关于Biztalk 2010:用大量同名元素映射 xsd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆