dataweave - For Loop dataweave mulesoft 问题
问题描述
我是 mulesoft 的新手,并且已经编写了 dataweave 来迭代订单项(xml 中的 product-lineitem)。但是,它不起作用,它只插入一个订单行项目,(订单行项目-product-lineitem)任何指针?
输入
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order xmlns="http://www.demandware.com/xml/impex/order/2006-10-31" order-no="00001101">
<order-date>2020-07-09T12:55:28.663Z</order-date>
<original-order-no>00001101</original-order-no>
<product-lineitems>
<product-lineitem>
<product-id>65754</product-id>
</product-lineitem>
<product-lineitem>
<product-id>65755</product-id>
</product-lineitem>
</product-lineitems>
</order>
数据编织
%dw 2.0
output application/java
ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
---
[{
Order_Confirmation_Number__c: payload.ns0#order.ns0#"current-order-no",
"attributes": {
"type": "PBSI__PBSI_Sales_Order__c",
"referenceId": "SO"
},
"PBSI__Sales_Order_Lines__r": {
"records": payload.*ns0#order.ns0#"product-lineitems" map((e,empindex) -> {
"attributes": {
"type": "PBSI__PBSI_Sales_Order_Line__c",
"referenceId": "SOL"
},
"PBSI__Item__c": "a0a1x000001PfWa",
"PBSI__ItemDescription__c": e.ns0#"product-lineitem".ns0#"product-id"
})
}
}]
解决方案
您需要*
为多值节点添加 ,即product-lineitem
您可以在输出中获取这两个值。更多详细信息:https ://docs.mulesoft.com/mule-runtime/4.3/dataweave-selectors
%dw 2.0
output application/java
ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
---
[{
Order_Confirmation_Number__c: payload.ns0#order.ns0#"original-order-no",
attributes: {
"type": "PBSI__PBSI_Sales_Order__c",
"referenceId": "SO"
},
PBSI__Sales_Order_Lines__r: {
records: payload.ns0#order.ns0#"product-lineitems".*ns0#"product-lineitem" map((e,empindex) -> {
"attributes": {
"type": "PBSI__PBSI_Sales_Order_Line__c",
"referenceId": "SOL"
},
"PBSI__Item__c": "a0a1x000001PfWa",
"PBSI__ItemDescription__c": e.ns0#"product-id"
})
}
}]
推荐阅读
- linux - pgaudit 扩展安装
- wpf - 如何以类似表格的格式显示符号?
- cpanel - 如何从旧备份文件中查看特定的数据库表?
- swift - 从字典中解析数据
在斯威夫特 - c# - 为什么 PartialView 模型在回发到 Asp.Net Core Razor 主页视图的控制器中为空?
- visual-studio-code - 如何在vs代码中显示python虚拟环境中创建的ipykernels?
- html - How can I make a Div fully push another div offscreen?
- reactjs - 路由确切路径 =“/”不适用于反应 github
- html - How can i make my Href image load 2 separate URLs
- javascript - 如何从 Javascript 中的字符串中分离出 URL?