首页 > 解决方案 > 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>

标签: dataweavemulesoftmule4

解决方案


你可以试试这个:

%dw 2.0
output application/json
---
payload..*"product-lineitem" map {
            "calcResult($$)": if($.."price-adjustment"?) "some calc" else "some other calc"
        }

推荐阅读