【问题标题】:trasfer one excel sheet into multiple xml content in mule将一张 excel 表格转换为 mule 中的多个 xml 内容
【发布时间】:2023-04-01 21:25:02
【问题描述】:

在 mule 中,我使用数据映射器将 excel 文件转换为 xml 文件。 数据映射器工作正常。但我想要一个不同xml格式的excel文件。

我的配置xml:

 <data-mapper:config name="ms_excel_to_xml_2" transformationGraphPath="ms_excel_to_xml_2.grf" doc:name="ms_excel_to_xml_2"/>
    <jms:activemq-connector name="Active_MQ1" brokerURL="tcp://10.16.20.132:61616" validateConnections="true" doc:name="Active MQ" password="manager" username="system" specification="1.1"/>
    <flow name="file-processFlow1" doc:name="file-processFlow1">
        <file:inbound-endpoint path="C:\Users\rajesh.narravula\Desktop\New folder" responseTimeout="10000" doc:name="File" fileAge="50000">
            <file:filename-regex-filter pattern=".*.xlsx" caseSensitive="false"/>
        </file:inbound-endpoint>
        <data-mapper:transform doc:name="MS Excel To XML" config-ref="ms_excel_to_xml_2" />
        <jms:outbound-endpoint doc:name="JMS" queue="OrchestratorQueue" connector-ref="Active_MQ1" responseTimeout="0">
            <jms:transaction action="ALWAYS_BEGIN" timeout="10000"/>
        </jms:outbound-endpoint>
    </flow>

这是我的excel文件内容:

caseType    claimNo status  customerName
------------------------------------------
CashLess      9     Open    Varun Arya
CashLess      9     Open    Varun Arya

我得到的实际 xml(在 datamapper 之后)是(作为字符串):

<?xml version="1.0" encoding="UTF-8"?>
<CashLess>
  <caseType>CashLess</caseType>
  <claimNo>9</claimNo>
  <status>Open</status>
  <customerName>Varun Arya</customerName>
</CashLess>
<CashLess>
  <caseType>CashLess</caseType>
  <claimNo>9</claimNo>
  <status>Open</status>
  <customerName>Varun Arya</customerName>
</CashLess>

预期是(多个字符串对象):

<?xml version="1.0" encoding="UTF-8"?>
<CashLess>
  <caseType>CashLess</caseType>
  <claimNo>9</claimNo>
  <status>Open</status>
  <customerName>Varun Arya</customerName>
</CashLess>

*another one*

<?xml version="1.0" encoding="UTF-8"?>
<CashLess>
  <caseType>CashLess</caseType>
  <claimNo>9</claimNo>
  <status>Open</status>
  <customerName>Varun Arya</customerName>
</CashLess>

请任何人帮助我想做什么改变。 谢谢。

【问题讨论】:

    标签: xml excel mule mule-studio


    【解决方案1】:

    在 DataMapper 之后放置一个带有 XPath 表达式的拆分器,并将每个单独的记录写入文件。

    http://www.mulesoft.org/documentation/display/current/Splitter+Flow+Control+Reference

    【讨论】:

      【解决方案2】:
      1. 1.将excel转成JSON。
      2. 将 JSON 转换为表达式。
      3. 使用集合分离器。
      4. 将对象转换为 JSON。
      5. 然后将 JSON 转换为 XML。

      示例代码:

      <data-mapper:config name="ms_excel_to_json_1" transformationGraphPath="ms_excel_to_json_1.grf" doc:name="ms_excel_to_json_1"/>
      <data-mapper:config name="json_to_xml" transformationGraphPath="json_to_xml.grf" doc:name="json_to_xml"/>
      <data-mapper:config name="json_to_xml_1" transformationGraphPath="json_to_xml_1.grf" doc:name="json_to_xml_1"/>
      <flow name="file-processFlow1" doc:name="file-processFlow1">
          <file:inbound-endpoint path="C:\Users\hello\Desktop\New folder" responseTimeout="10000" doc:name="File" fileAge="50000">
              <file:filename-regex-filter pattern=".*.xlsx" caseSensitive="false"/>
          </file:inbound-endpoint>
          <data-mapper:transform config-ref="ms_excel_to_json_1" doc:name="MS Excel To JSON"/>
          <json:json-to-object-transformer returnClass="java.util.List" doc:name="JSON to Object"/>
          <expression-transformer expression="#[message.payload]" doc:name="Expression"/>
          <collection-splitter doc:name="Collection Splitter"/>
          <json:object-to-json-transformer doc:name="Object to JSON"/>
          <data-mapper:transform config-ref="json_to_xml_1" doc:name="JSON To XML"/>
          <object-to-string-transformer doc:name="Object to String"/>
      </flow>
      

      【讨论】:

        猜你喜欢
        • 2023-03-26
        • 2022-01-08
        • 2017-05-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多