简体   繁体   中英

Anypoint Studio problem with JSON into XML transformation

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.

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
            }
        }
    }
}

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