Dataweave 到 select 来自 XML Mulesoft 的精确标签
Dataweave to select exact tag from XML Mulesoft
从下面的 XML 得到“0011x000014VegoAAC”的正确 Dataweave 表达式是什么?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000907" xmlns="http://www.demandware.com/xml/impex/order/2006-10-31">
<order-date>2020-07-10T08:57:05.076Z</order-date>
<current-order-no>00000907</current-order-no>
<product-lineitems>
<product-lineitem>
<net-price>54.17</net-price>
</product-lineitem>
</product-lineitems>
<custom-attributes>
<custom-attribute attribute-id="Adyen_pspReference">852594371442812G</custom-attribute>
<custom-attribute attribute-id="Adyen_value">7099</custom-attribute>
<custom-attribute attribute-id="sscAccountid">0011x000014VegoAAC</custom-attribute>
</custom-attributes>
</order>
自定义属性看起来像标准标记。将其包装到引号中,它将正常工作。 custom-attribute 是一个数组,在 DW 转换中用星号表示。从这个数组(第 19 行创建它)我们过滤所有属性(由 @ 字符表示)等于 sscAccountId 的项目。
结果是一个只有一个元素的数组。
%dw 2.0
var payload =read('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000907" xmlns="http://www.demandware.com/xml/impex/order/2006-10-31">
<order-date>2020-07-10T08:57:05.076Z</order-date>
<current-order-no>00000907</current-order-no>
<product-lineitems>
<product-lineitem>
<net-price>54.17</net-price>
</product-lineitem>
</product-lineitems>
<custom-attributes>
<custom-attribute attribute-id="Adyen_pspReference">852594371442812G</custom-attribute>
<custom-attribute attribute-id="Adyen_value">7099</custom-attribute>
<custom-attribute attribute-id="sscAccountid">0011x000014VegoAAC</custom-attribute>
</custom-attributes>
</order>','application/xml')
output application/json
---
(payload.order."custom-attributes".*"custom-attribute")
filter (item) -> (item.@"attribute-id" ~= "sscAccountid")
从下面的 XML 得到“0011x000014VegoAAC”的正确 Dataweave 表达式是什么?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000907" xmlns="http://www.demandware.com/xml/impex/order/2006-10-31">
<order-date>2020-07-10T08:57:05.076Z</order-date>
<current-order-no>00000907</current-order-no>
<product-lineitems>
<product-lineitem>
<net-price>54.17</net-price>
</product-lineitem>
</product-lineitems>
<custom-attributes>
<custom-attribute attribute-id="Adyen_pspReference">852594371442812G</custom-attribute>
<custom-attribute attribute-id="Adyen_value">7099</custom-attribute>
<custom-attribute attribute-id="sscAccountid">0011x000014VegoAAC</custom-attribute>
</custom-attributes>
</order>
自定义属性看起来像标准标记。将其包装到引号中,它将正常工作。 custom-attribute 是一个数组,在 DW 转换中用星号表示。从这个数组(第 19 行创建它)我们过滤所有属性(由 @ 字符表示)等于 sscAccountId 的项目。
结果是一个只有一个元素的数组。
%dw 2.0
var payload =read('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000907" xmlns="http://www.demandware.com/xml/impex/order/2006-10-31">
<order-date>2020-07-10T08:57:05.076Z</order-date>
<current-order-no>00000907</current-order-no>
<product-lineitems>
<product-lineitem>
<net-price>54.17</net-price>
</product-lineitem>
</product-lineitems>
<custom-attributes>
<custom-attribute attribute-id="Adyen_pspReference">852594371442812G</custom-attribute>
<custom-attribute attribute-id="Adyen_value">7099</custom-attribute>
<custom-attribute attribute-id="sscAccountid">0011x000014VegoAAC</custom-attribute>
</custom-attributes>
</order>','application/xml')
output application/json
---
(payload.order."custom-attributes".*"custom-attribute")
filter (item) -> (item.@"attribute-id" ~= "sscAccountid")