I need help to convert an input XML into an XML output on a single line, that is without spaces, without line breaks and without tabs.
That is to say show the data followed in one line. Could you please help me, please?
The following sample XML would be the input:
<tns:ResponseMessage xmlns:n1="urn:sap-com:document:sap:rfc:functions" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<tns:Header>
<tns:Verb>reply</tns:Verb>
<tns:Noun>Compressed</tns:Noun>
<tns:User/>
<Signature xmlns="">
<SignedInfo>
<CanonicalizationMethod Algorithm=""/>
<SignatureMethod Algorithm=""/>
</SignedInfo>
<SignatureValue>XW8UqTTcR==</SignatureValue>
<KeyInfo>
<X509Data>
<X509IssuerSerial>
<X509IssuerName></X509IssuerName>
<X509SerialNumber>1448033456</X509SerialNumber>
</X509IssuerSerial>
<X509SubjectName></X509SubjectName>
<X509Certificate>MIIF8z</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
</tns:Header>
<tns:Reply>
<tns:Result>OK</tns:Result>
<tns:ID idAuthority="" idType="" kind="" objectType=""/>
<tns:operationId>0</tns:operationId>
</tns:Reply>
<tns:Payload>
<tns:OperationSet>
<tns:enforceMsgSequence>false</tns:enforceMsgSequence>
</tns:OperationSet>
<tns:Compressed>QlpoORdyRThQkAA=</tns:Compressed>
</tns:Payload>
</tns:ResponseMessage>
The following output is expected:
{body:<tns:ResponseMessage xmlns:n1="urn:sap-com:document:sap:rfc:functions" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"><tns:Header><tns:Verb>reply</tns:Verb><tns:Noun>Compressed</tns:Noun><tns:User/><Signature xmlns=""><SignedInfo><CanonicalizationMethod Algorithm=""/><SignatureMethod Algorithm=""/></SignedInfo><SignatureValue>XW8UqTTcR==</SignatureValue><KeyInfo><X509Data><X509IssuerSerial><X509IssuerName></X509IssuerName><X509SerialNumber>1448033456</X509SerialNumber></X509IssuerSerial><X509SubjectName></X509SubjectName><X509Certificate>MIIF8z</X509Certificate></X509Data></KeyInfo></Signature></tns:Header><tns:Reply><tns:Result>OK</tns:Result><tns:ID idAuthority="" idType="" kind="" objectType=""/><tns:operationId>0</tns:operationId></tns:Reply><tns:Payload><tns:OperationSet><tns:enforceMsgSequence>false</tns:enforceMsgSequence></tns:OperationSet><tns:Compressed>QlpoORdyRThQkAA=</tns:Compressed></tns:Payload></tns:ResponseMessage>}
The transformation I’m looking for is in DataWeave 2.0 for Mule 4.
You can remove the indentation of an input XML with the
indent=falsewrite property of the XML format, however that doesn't remove new lines. For that you can convert the XML into a String then do character replacement. Note that with or without those characters the XML is equally valid.