在mule我正在使用data-mapper将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之后)是(作为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>
期望是(多个String对象):
<?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>
请任何人帮助我想做什么改变。 感谢。
答案 0 :(得分:0)
在DataMapper之后放置一个带有XPath表达式的拆分器,并将每个单独的记录写入文件。
http://www.mulesoft.org/documentation/display/current/Splitter+Flow+Control+Reference
答案 1 :(得分:0)
示例代码:
<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>