Get XML payload size in MB

77 Views Asked by At

I need to check the size of incoming payload that is in the XML format in MB. And if size is over certain MB (example 50 MB) I need to route the flows using choice router. I have issues checking the size of the incoming payload. I tried writing the below code in dataweave but its giving me errors:

%dw 2.0
output application/json
var someXml = read(payload, "application/xml")
---
{
Size: sizeOf(write(someXml, "application/xml"))
}

Below is the sample request XML that I am trying to read and check its size:

<root>
    <simple>
        <account>
            <No>123456789</No>
            <IDNumber>129</IDNumber>
        </simple>
    </account>
</root>
1

There are 1 best solutions below

0
Mariano de Achaval On

You can use

sizeOf(payload.^raw)

This will return the size of the underlying stream without the need of parsing or re write