trasfer one excel sheet into multiple xml content in mule

最后都变了- 提交于 2019-12-13 04:22:08

问题


In mule I'm using data-mapper to convert excel file to xml file. data mapper is working fine. But i want one excel file different xml format.

My configuration 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>

This is my excel file content:

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

Actual xml(after datamapper) I'm getting was(as String):

<?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>

expected is(Multiple String objects):

<?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>

Please any one help what changes i want to do. Thanks.


回答1:


Place a splitter with an XPath expression after DataMapper and write each individual record to a file.

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




回答2:


  1. 1.Convert excel to JSON.
  2. Convert JSON to expression.
  3. Use collection-splitter.
  4. convert Object to JSON.
  5. Then convert JSON to XML.

sample code:

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



来源:https://stackoverflow.com/questions/21901408/trasfer-one-excel-sheet-into-multiple-xml-content-in-mule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!