My current payload is (received from a POST)
<?xml version='1.0' encoding='ISO-8859-1'?>
<test>
</test>
I want to get the encoding value (ie ISO-8859-1
)
What is the correct DataWeave expression to use ?
I already tested
var infos = payload.^mediaType splitBy "; "
var encoding = infos[1] splitBy "="
---
media:
{
mime: infos[0],
encoding: encoding[1]
}
But it return me:
{
"mime": "application/xml",
"encoding": "UTF-8"
}
It seems payload.^mediaType
is coming from my POST headers.
Here is the solution to the problem:
%dw 2.0
output application/java
---
((payload.^raw as String) scan /encoding='([A-z0-9-]+)'/)[0][1]
In the proposed solution the ^ symbol is missing.
Sadly there is no elegant way to do this. The only way I thought is by using regex.
%dw 2.0
output application/java
---
((payload.^raw as String) scan /encoding='([A-z0-9-]+)'/)[0][1]
This is going to return the encoding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With