Biztalk:将Excel文件OutXML(嵌套列)映射到自定义架构。

时间:2018-01-18 06:53:07

标签: xml excel biztalk biztalk-mapper

我创建了一个自定义管道组件,它使用OpenXML方法here从Excel工作簿中提取XML数据。工作簿中的“原始”XML具有此模式(从上面引用的OpenXML代码中提取的XML实例生成:

    <?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import schemaLocation=".\Smart Recruiters_ExcelRawXML.xsd" namespace="http://www.w3.org/XML/1998/namespace" />
  <xs:annotation>
    <xs:appinfo>
      <references xmlns="http://schemas.microsoft.com/BizTalk/2003">
        <reference targetNamespace="http://www.w3.org/XML/1998/namespace" />
      </references>
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="dimension">
          <xs:complexType>
            <xs:attribute name="ref" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element name="sheetViews">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="sheetView">
                <xs:complexType>
                  <xs:attribute name="tabSelected" type="xs:boolean" use="required" />
                  <xs:attribute name="workbookViewId" type="xs:unsignedByte" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="sheetFormatPr">
          <xs:complexType>
            <xs:attribute name="defaultRowHeight" type="xs:decimal" use="required" />
          </xs:complexType>
        </xs:element>
        <xs:element name="sheetData">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="unbounded" name="row">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="c">
                      <xs:complexType>
                        <xs:sequence minOccurs="0">
                          <xs:element name="is">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element name="t">
                                  <xs:complexType>
                                    <xs:simpleContent>
                                      <xs:extension base="xs:string">
                                        <xs:attribute ref="xml:space" use="optional" />
                                      </xs:extension>
                                    </xs:simpleContent>
                                  </xs:complexType>
                                </xs:element>
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                        <xs:attribute name="r" type="xs:string" use="required" />
                        <xs:attribute name="s" type="xs:unsignedByte" use="required" />
                        <xs:attribute name="t" type="xs:string" use="optional" />
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="r" type="xs:unsignedShort" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="pageMargins">
          <xs:complexType>
            <xs:attribute name="left" type="xs:decimal" use="required" />
            <xs:attribute name="right" type="xs:decimal" use="required" />
            <xs:attribute name="top" type="xs:decimal" use="required" />
            <xs:attribute name="bottom" type="xs:decimal" use="required" />
            <xs:attribute name="header" type="xs:decimal" use="required" />
            <xs:attribute name="footer" type="xs:decimal" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

第一行中第一个元素的示例是:

<x:row r="1"><x:c r="A1" s="1" t="inlineStr"><x:is><x:t>ID</x:t></x:is>

我的问题是,如何在mapper中使用迭代列记录并将每个行/列值应用到目标XML中的正确行/字段(如下)。我在线搜索但我没有看到任何可以评估行并应用于正确的目标行/字段的内容。假设输入将始终具有正确的列数,即使'c'被声明为无界限。

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Schemas.SmartRecruiters_Joibs_Manual" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Schemas.SmartRecruiters_Joibs_Manual" 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="postfix" 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 maxOccurs="unbounded" name="Root_Child1">
          <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="Root_Child1_Child1" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="1" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Root_Child1_Child2" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="2" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Root_Child1_Child3" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="3" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

2 个答案:

答案 0 :(得分:1)

您需要为每个目标行使用值映射。

enter image description here

作为第一个参数的输入是验证原点的行和列是否符合预期的结果(在这种情况下,r = 1且c.r = A1)。

第二个参数是您要分配的值。

答案 1 :(得分:1)

我认为你有点过分了。

通过循环Functoid <row>链接到<Root_Child1>。那会在行上循环,价值无关紧要......除非你真的需要它。

然后,通过 Index Functoid 连接<t>,从中选择第n个<c>来获取值。