Dataweave syntax for SOAP XML format

Viewed 36

I'm trying to write a DataWeave that would represent this XML:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xsi:xsd="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
    <AuthenticateResult xmlns="urn:authentication.soap.sforce.com">
        <Authenticated>true</Authenticated>
    </AuthenticateResult>
</soapenv:Body>
</soapenv:Envelope>

And I'm having a really hard time seeing if there are ns and other XML native syntax values supported via DW, or declare custom variables in DataWeave.

%dw 2.0
output application/xml
ns soapenv http://schemas.xmlsoap.org/soap/envelope/
ns xsi http://www.w3.org/2001/XMLSchema-instance
---
{
    soapenv#Envelope 
    @(xsi#xsd:"http://schemas.xmlsoap.org/soap/envelope/"): {
        soapenv#Body: {
            AuthenticateResult @(xmlns: "urn:authentication.soap.sforce.com"): {
                Authenticated: payload.login
            }
        }
    }
}

my payload is just this, I want it to get updated from either true or false:

{
    "login": "true"
}
1 Answers

You can use @ the same way to define more ns as you have done with AuthenticateResult

%dw 2.0
output application/xml
ns soapenv http://schemas.xmlsoap.org/soap/envelope
---
{
    soapenv#Envelope @("xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", "xsi:xsd":"http://schemas.xmlsoap.org/soap/envelope/"): {
        soapenv#Body: {
            AuthenticateResult @(xmlns: "urn:authentication.soap.sforce.com"): {
                Authenticated: payload.login
            }
        }
    }
}
Related