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.