简体   繁体   中英

DataWeave transformation issue in esb mule

I have transformation in dataweave.

I am getting input from the Mysql database. Input payload type is List- Map. My dataweave editer has below code.

%dw 1.0
%namespace ns1 urn:abc:api:Components
%output application/xml 
---
ns1#"ItemRequest":{
    ns1#"Requester":
        ns1#ac: payload.time_max,

        ns1#"ErrorLanguage": "en_US",
        ns1#"WarningLevel": "High"
}

My output is

<?xml version='1.0' encoding='UTF-8'?>
<ns1:ItemRequest xmlns:ns1="urn:abc:api:Components">
  <ns1:Requester>
    <ns1:ac>
      <time_max>1</time_max>
    </ns1:ac>
  </ns1:Requester>
  <ns1:ErrorLanguage>en_US</ns1:ErrorLanguage>
  <ns1:WarningLevel>High</ns1:WarningLevel>
</ns1:AddItemRequest>

I am not sure why i am getting tag created under'ac' element in my output with 'time_max'. The 'Time_max' is the column name in MySQL table. But i dont want to add the column in the output xml. How can we avoid this tag creation ?

Expected output is

<?xml version='1.0' encoding='UTF-8'?>
<ns1:ItemRequest xmlns:ns1="urn:abc:api:Components">
  <ns1:Requester>
    <ns1:ac>1</ns1:ac>
  </ns1:Requester>
  <ns1:ErrorLanguage>en_US</ns1:ErrorLanguage>
  <ns1:WarningLevel>High</ns1:WarningLevel>
</ns1:AddItemRequest>

I have resolved the issue by typing below code.

%dw 1.0
%namespace ns1 urn:abc:api:Components
%output application/xml 
---
ns1#"ItemRequest":{
    ns1#"Requester":
        ns1#ac: payload[0].time_max,
        ns1#"ErrorLanguage": "en_US",
        ns1#"WarningLevel": "High"
}

The below line of snippet is did magic. I have included array index values.

 ns1#ac: payload[0].time_max

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM