You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mule 4处理大XML文件报错求助及替代方案咨询

处理Mule 4中300MB大XML文件的流式处理问题

问题背景

我在Mule 4中处理一个约300MB的大XML文件,尝试用流式拆分方案处理,但遇到了一系列错误:

初始错误

For Each组件抛出错误:

脚本语言表达式'%dw 2.0 output application/xml --- payload.file'执行错误:无法调用值选择器,参数为(Binary, file),原因:期望类型为Object,实际为Binary;期望类型为Array,实际为Binary。

更新后的错误

我尝试添加变量以XML mime类型保存payload,再将payload设置为该变量(同样指定XML mime类型),现在For Each组件报错:

"Trying to output second root, <record>, while writing Xml at ." evaluating expression: "%dw 2.0 output application/xml --- payload.file".

错误截图

我推测问题源于File Read组件输出Binary类型,尝试在Read后、For Each前使用Transform组件,但处理耗时过长。

输入XML文件结构示例

<file>
 <record>
  <WORK_ORDER>123</WORK_ORDER>
  <DESC>TEXT1</DESC>
  <STATUS_M>0</STATUS_M>
  <CODE>code1</CODE>
 </record>
 <record>
  <WORK_ORDER>124</WORK_ORDER>
  <DESC>TEXT2</DESC>
  <STATUS_M>1</STATUS_M>
  <CODE>code2</CODE>
 </record>
 <record>
  <WORK_ORDER>125</WORK_ORDER>
  <DESC>TEXT3</DESC>
  <STATUS_M>0</STATUS_M>
  <CODE>code3</CODE>
 </record>
</file>

当前Mule Flow代码

<flow name="streaming-poc-flow" doc:id="2b5e68a5-e3a9-4c7a-a114-c9516e9ac33e" >
    <scheduler doc:name="Scheduler" doc:id="a86b544d-d72e-4e11-8adf-aecc6f61d515" >
        <scheduling-strategy >
            <fixed-frequency frequency="5" timeUnit="MINUTES"/>
        </scheduling-strategy>
    </scheduler>
    <file:read doc:name="Read" doc:id="c6ddc341-0808-416a-935a-4d1fac9deafb" config-ref="File_Config" path="D:\unittest\WorkOrder.XML" outputMimeType="application/xml; streaming=true; collectionpath=file.record" target="varsXML">
        <non-repeatable-stream />
    </file:read>
    <set-payload value="#[vars.varsXML]" doc:name="Set Payload" doc:id="7a30359a-5989-4401-ac8b-c90e3cfd4d9d" mimeType="application/xml"/>
    <foreach doc:name="For Each" doc:id="75df909d-2ee1-4439-a987-168ed7d2408e" collection="#[%dw 2.0 &#10;output application/xml &#10;--- &#10;payload.file]" batchSize="100" rootMessageVariableName="record">
        <logger level="INFO" doc:name="Logger" doc:id="de3f5603-a0e4-4234-b5bc-b61ab52b74db" message="File output: #[payload]" />
    </foreach>
</flow>

提问

请问是否有其他可行的方法来处理这类大文件?

内容的提问来源于stack exchange,提问作者Abjt G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 03:25:28