首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dataweave从XML Mulesoft中选择精确的标签

Dataweave从XML Mulesoft中选择精确的标签
EN

Stack Overflow用户
提问于 2020-07-10 22:28:35
回答 1查看 288关注 0票数 0

从下面的XML中获取"0011x000014VegoAAC“的正确Dataweave表达式是什么?

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-10 23:09:07

Custom-attribute看起来像标准标记。将它封装到引号中,它就会工作得很好。custom-attribute是一个在DW转换中用星号表示的数组。从这个数组(第19行创建它)中,我们过滤属性(由@character表示)等于sscAccountId的所有项。

结果是只有一个元素的数组。

代码语言:javascript
复制
%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")

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62836472

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档