0
votes

I have the following json data and I want to convert to xml as it is. Is there a way simplest way to do it in mule data weave

 {
      "Header": {
        "Date": "20160721145839",
        "UTC_Time": null,
        "TransactionDateTime": "20160721145839",
        "EventType": "Test",
        "PlaceOfEvent": "AUD",
        "RefNo": "SHPL123123",
        "SenderUserName": "APINAR"        
      },
      "Body": {
        "Number": "ZZZZ",

        "vfgt": 2000,
        "Decwt": 0,
        "Status": "F",
        "Category": "E",
        "AdditionalData": {
          "MethodOfWeightCalculation": "SM2",
          "wtData": {
            "Country": "AU"
          },
          "Declarant": {
            "DeclarantPhone": "55555555"
          },
          "EDISignature": "x"
        }
      }
    }

When I try something like below its giving me error in mule

%dw 1.0
%output application/xml skipNullOn="everywhere"
---
payload
4

4 Answers

1
votes

You require root element for xml transformation. There is no problem with json input. Following works fine.

%dw 1.0
%output application/xml
---
root : payload

Hope this helps.

0
votes

This may help you and if it doesn't work please let me know:

%dw 1.0
%output application/xml
---
root:payload
0
votes

You can try giving a name to root elements and give the payload.

%dw 1.0

%output application/xml

Myroot:payload

-2
votes

XML starts at "the root" and branches to "the leaves". So for xml transformation we require root element.

%dw 1.0

%output application/xml

root:payload

I hope this will help you.