I need to get a XML SOAP envelope as result of a MS SQL Server query, like this one:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:usercontrol">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<urn:Action>
<urn:CDUSER>2</urn:CDUSER>
<urn:IDUSER>jd</urn:IDUSER>
<urn:NMUSER>John Doe</urn:NMUSER>
<urn:DTINSERT>2019-09-12</urn:DTINSERT>
</urn:Action>
</soapenv:Body>
</soapenv:Envelope>
My query:
WITH XMLNAMESPACES ('urn:usercontrol' AS urn, 'http://schemas.xmlsoap.org/soap/envelope/' AS soapenv)
SELECT
'' AS [soapenv:Header],
(
SELECT
CDUSER AS [urn:CDUSER],
IDUSER AS [urn:CDUSER],
NMUSER AS [urn:CDUSER],
CONVERT(varchar, DTINSERT, 120) AS [urn:DTINSERT]
FROM
ADUSER
WHERE
CDUSER = 2
FOR XML PATH('urn:newAction')
) AS [soapenv:Body]
FOR XML PATH('soapenv:Envelope')
Well, the result is not far away, but not what I want:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:usercontrol">
<soapenv:Header></soapenv:Header>
<soapenv:Body><urn:newAction xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:usercontrol"><urn:CDUSER>2jdJohn Doe</urn:CDUSER><urn:DTINSERT>2019-09-12 11:09:45</urn:DTINSERT></urn:newAction></soapenv:Body>
</soapenv:Envelope>
Can you help me? Many thanks, in advance.