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

Mule 4中使用DataWeave 2将XML负载转换为指定结构JSON的方法

解决方案

你可以直接使用如下DataWeave 2脚本完成转换:

%dw 2.0
output application/json
---
payload.Report_Data.*Report_Entry map (reportItem) -> {
    empl_id: reportItem.Employee_ID,
    teamManager: reportItem.*Manager_Of_Team map (team) -> 
        (team.*ID filter ($.@'wd:type' == "Organization_Reference_ID"))[0]
}

关键逻辑说明

  • 使用*选择器匹配所有同名节点:*Report_Entry会把所有员工节点统一返回为数组,*Manager_Of_Team同理,不管单个还是多个管理者节点都统一按数组处理,不需要额外用flatten处理结构
  • 对每个团队管理者节点,从其下的ID数组中筛选出wd:type为Organization_Reference_ID的节点,取其文本值就是你需要的组织ID
  • 如果担心存在无效的管理者节点导致返回null,可在teamManager数组最后加filter $ != null过滤空值

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 12:39:04