我需要帮助将输入 XML 转换为单行 XML 输出,即没有空格、没有换行符和没有制表符。
即一行显示后面的数据。你能帮帮我吗?
以下示例 XML 将作为输入:
<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>
预期输出如下:
{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>}
我正在寻找的转换是在 DataWeave 2.0 for Mule 4.
您可以使用 XML 格式的
indent=false
写入属性删除输入 XML 的缩进,但这不会删除新行。为此,您可以将 XML 转换为字符串,然后进行字符替换。请注意,无论有无这些字符,XML 都同样有效。
%dw 2.0
output application/java
---
write(payload,"application/xml",{indent:false}) replace "\n" with ""