2

I am trying to convert JSON response into XML and then call SOAP API with payload. I managed to get JSON response without any trouble, but I am unable to convert it to XML. the problem is data has to be in format:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <NumberToDollars xmlns="http://www.dataaccess.com/webservicesserver/">
      <dNum>47.92</dNum>
    </NumberToDollars>
  </soap:Body>
</soap:Envelope> 

but when I use this as example for Transform Messages module it creates:

%dw 2.0
output application/xml
ns ns00 http://schemas.xmlsoap.org/soap/envelope/
ns ns01 http://www.dataaccess.com/webservicesserver/
---
{
    ns00#Envelope: {
        ns00#Body: {
            ns01#NumberToDollars: {
                ns01#dNum: payload.decimal
            }
        }
    }
}

and when I use a Logger to view the output it is:

<?xml version='1.0' encoding='UTF-8'?>
<ns00:Envelope xmlns:ns00="http://schemas.xmlsoap.org/soap/envelope/">
  <ns00:Body>
    <ns01:NumberToDollars xmlns:ns01="http://www.dataaccess.com/webservicesserver/">
      <ns01:dNum>47.92</ns01:dNum>
    </ns01:NumberToDollars>
  </ns00:Body>
</ns00:Envelope>

I know I can change it manually and I managed to get it to look like this:

%dw 2.0
output application/xml
ns soap http://schemas.xmlsoap.org/soap/envelope/
ns ns01 http://www.dataaccess.com/webservicesserver/
---
{
    soap#Envelope: {
        soap#Body: {
            NumberToDollars: {
                dNum: payload.decimal
            }
        }
    }
}

output:

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <NumberToDollars>
      <dNum>47.92</dNum>
    </NumberToDollars>
  </soap:Body>
</soap:Envelope>

But I have no idea how to get NumberToDollarsbe without namespace and at the same time to have xmlns link (how can I get rid of ns00 and at the same time keeping the link).

I checked all there was about it in Mule Documentation and found nothing please, please help.

aled
  • 21,330
  • 3
  • 27
  • 34
Curiosity
  • 81
  • 6

1 Answers1

1

A way to do that is to define xmlns as if it were a normal attribute:

%dw 2.0
output application/xml
ns ns00 http://schemas.xmlsoap.org/soap/envelope/
ns ns01 http://www.dataaccess.com/webservicesserver/
---
{
    ns00#Envelope: {
        ns00#Body: {
            NumberToDollars @(xmlns: "http://www.dataaccess.com/webservicesserver/"): {
                dNum: payload.decimal
            }
        }
    }
}
aled
  • 21,330
  • 3
  • 27
  • 34
  • 1
    Thank you for your response, now I have one last question. Is there a way for me to save this response? Because when I make `Consume` after that it for some reason deletes Envelope and Body tags (I think) and returns `Error processing request: No such method: Envelope`. I tried to save it to variable but it does the same thing. – Curiosity Dec 20 '21 at 21:45
  • 1
    I would also be grateful if you could explain to me why when I call #[payload] it changes how it looked before and I have to deal again with adding xmlns the way you showed me and change ns00 to soap... – Curiosity Dec 20 '21 at 21:52
  • 1
    Consume as in the Web Service Consumer? That is not part of the original question. Please post a new question and I'll be happy to try to help. – aled Dec 21 '21 at 00:00
  • 1
    Same for the `#[payload]` question. Please provide the details (input, output) so we can understand the issue. – aled Dec 21 '21 at 00:05