dataweave - Dataweave 中是否存在 XML 标签
问题描述
我想<price-adjustments>
在 Mule 4 的 Dataweave 2.0 中检查以下 XML 中是否存在标签。如何实现这一点?
我在下面尝试,但它给了我语法错误:
(payload.ns0#order.ns0#"product-lineitems".*ns0#"product-lineitem" map( e , lineindex ) -> {
if(e.price-adjustments != null || e.price-adjustments != "") e."price-adjustments"."base-price" - (e."price-adjustments"."tax"/e."price-adjustments".quantity") else e.ns0#"base-price" - (e.ns0#"tax"/e.ns0#"quantity")
}
XML
<?xml version="1.0" encoding="UTF-8"?>
<order xmlns="http://www.demandware.com/xml/impex/order/2006-10-31" version="20.8" order-no="00002404">
<order-date>2021-03-08T15:20:32.084Z</order-date>
<product-lineitems>
<product-lineitem>
<net-price>487.60</net-price>
</product-lineitem>
<product-lineitem>
<net-price>53.72</net-price>
<price-adjustments>
<price-adjustment>
<net-price>-53.72</net-price>
</price-adjustment>
</price-adjustments>
</product-lineitem>
</product-lineitems>
</order>
解决方案
你可以试试这个:
%dw 2.0
output application/json
---
payload..*"product-lineitem" map {
"calcResult($$)": if($.."price-adjustment"?) "some calc" else "some other calc"
}
推荐阅读
- html - *ngIf & Jquery 行为怪异 - Angular 5
- c# - 如何在 VS 2017 中使用 EF 6.x EntityObject Generator
- html - Angular 6 路由器插座样式应用于其下方的元素
- python - 如何从路径动态导入python
- google-maps - 在不加载整个地图的情况下更新谷歌地图中的标记
- linked-list - Fortran 保持头部指向第一个元素/添加到列表的尾部
- angularjs - ng-if on ng-repeat value angular js
- computer-vision - SPLUNK 子搜索 2 个 CSV 文件连接在一起
- hyperledger-fabric - 运行 Fabric 示例 e2e_cli network_setup.sh 时出错
- dpdk - 无法使用 dpdk 创建 mbuf 池