开发者

Biztalk 2010: mapping an xsd with a lot of elements with the same name

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>

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=&quo开发者_运维问答t;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>

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).

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)

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).

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


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

And BizTalk creates the XSLT for you anyway :)

So would recommend:

  • 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'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)

Edit : Note that the above is for BizTalk 2009

Edit

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.


A simpler way to get the generated xlst (and generally the recommended way that has worked since at least bts2006) is to right-click the btm file in your solution explorer and choose "validate map". The output of this gives you both the xslt and the extension objects in standalone files (certain functoids and external class references use an extension objects file).

From here you can save off and modify the xslt output - don't need to parse the .btm.cs file or worry about string encoding issues like missing an escaped double quote around an attribute or a namespace...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜