I have an XML and I want to check in Dataweave if a <custom-attribute attribute-id="sscAccountid">0011x0000152nlyAAA</custom-attribute>
tag exist in XML, how to do that?
<?xml version="1.0" encoding="UTF-8"?>
<order xmlns="http://www.demandware.com/xml/impex/order/2006-10-31" order-no="00001503">
<order-date>2020-07-24T13:15:09.654Z</order-date>
<created-by>storefront</created-by>
<original-order-no>000015034</original-order-no>
<customer>
<customer-no>00000001</customer-no>
<billing-address>
<first-name>abc</first-name>
<last-name>Chioda</last-name>
<address1>via Venezia 55</address1>
<phone>+444</phone>
</billing-address>
</customer>
<custom-attributes>
<custom-attribute attribute-id="Adyen_pspReference">882595596510490G</custom-attribute>
<custom-attribute attribute-id="Adyen_value">29999</custom-attribute>
<custom-attribute attribute-id="sscAccountid">0011x0000152nlyAAA</custom-attribute>
<custom-attribute attribute-id="sscSyncResponseText">
<value>Successfully Exported</value>
</custom-attribute>
<custom-attribute attribute-id="sscSyncStatus">exported</custom-attribute>
<custom-attribute attribute-id="sscid">8011x00000QaOFwAAN</custom-attribute>
</custom-attributes>
</order>
I understand that you want to confirm if an XML payload with the structure of your example has an order.custom-attributes.custom-attribute element with attribute attribute-id equal "sscAccountid".
%dw 2.0
output application/json
fun hasAccountId(x) =sizeOf(x.order.'custom-attributes' filterObject ($.@'attribute-id' == "sscAccountid") ) > 0
---
hasAccountId(payload)
Output for your input XML:
true