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

WSO2中介器问题:如何遍历解析多日期格式表名的年月日?

解决WSO2中介器遍历多表名解析问题

核心问题根因

当前仅解析出第一个表名,是因为你的Enrich Mediator未对返回的表名列表做遍历迭代处理,默认仅匹配并处理了第一个表节点。

具体解决步骤

1. 用Iterate Mediator实现列表遍历

在Enrich处理逻辑前,添加Iterate Mediator循环每个表名节点,让每个表名都能被单独解析:

<iterate expression="//tableNames/table" id="tableIteration" sequential="true">
    <target>
        <sequence>
            <!-- 单个表名的年月日解析逻辑 -->
            <enrich>
                <source type="body" xpath="substring(., 1, 4)"/>
                <target type="property" property="year"/>
            </enrich>
            <enrich>
                <source type="body" xpath="substring(., 5, 2)"/>
                <target type="property" property="month"/>
            </enrich>
            <enrich>
                <source type="body" xpath="substring(., 7, 2)"/>
                <target type="property" property="day"/>
            </enrich>
            <!-- 输出当前表的解析结果 -->
            <log level="custom">
                <property name="Current Table" expression="."/>
                <property name="Year" expression="$ctx:year"/>
                <property name="Month" expression="$ctx:month"/>
                <property name="Day" expression="$ctx:day"/>
            </log>
            <!-- 可选:聚合所有解析结果 -->
            <aggregate id="tableIteration">
                <completeCondition>
                    <messageCount max="-1" min="-1"/>
                </completeCondition>
                <onComplete expression="//parsedTables">
                    <!-- 聚合后的结果处理逻辑 -->
                </onComplete>
            </aggregate>
        </sequence>
    </target>
</iterate>

2. 修正XPath定位逻辑

  • 确认API返回的表名结构,比如如果返回是<tableNames><table>20221018</table><table>20221211</table></tableNames>,Iterate的expression="//tableNames/table"可正确遍历每个表节点。
  • Enrich的XPath中使用.替代//table,因为Iterate已将单个表节点作为当前消息体,避免全局匹配第一个节点。

3. 配置聚合逻辑(可选)

如果需要汇总所有解析后的年月日数据,用Aggregate Mediator配合Iterate的ID,在onComplete节点中处理聚合结果。

关键注意点

  • Iterate的sequential设为true可保证顺序处理,若无需顺序可设为false提升性能。
  • 检查日志输出的XPath是否指向当前迭代的表节点,避免始终读取第一个节点的问题。

内容的提问来源于stack exchange,提问作者rania ben salem

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 15:45:34