Simbu
Simbu

Reputation: 796

Output Encoding issue in mule esb

I have used to do create XML using "Transform Message" Node in Mule ESB.

%dw 1.0 %output application/xml

item: { name: payload."profile_name", id: payload."profile_Id" }

This shown a preview of output xml as

<?xml version='1.0' encoding='windows-1252'?>
<item>
  <name>
    <profile_name>????</profile_name>
  </name>
  <id>
    <profile_Id>1</profile_Id>
  </id>
</item>

This resulted encoding as 'windows-1252' how can i change encoding as 'UTF-8' in my outpout xml ?

Upvotes: 1

Views: 5617

Answers (3)

Gorodeckij Dimitrij
Gorodeckij Dimitrij

Reputation: 4636

For dataweave in runtime above 3.8.4 I implemented this solution:

  1. set output as variable:

Output FlowVar - fv_itemName_xml

  1. inside of Transform Message:

    '%output application/xml writeDeclaration=false

    item: { name: payload."profile_name", id: payload."profile_Id" }

and output will be:

<item>
  <name>
    <profile_name>????</profile_name>
  </name>
  <id>
    <profile_Id>1</profile_Id>
  </id>
</item>
  1. Then define a variable as below:

    Name: fv_outputName_xml

    Value: #[flowVars.fv_itemName_xml]

    Encoding: ISO 10646/Unicode(UTF-8)

    Mime type: application/xml

And you have better control of Encoding and Mime type.

In my case I was need to feed that into Stored Procedure and without this workarround constantly receiving error:

System.Data.SqlClient.SqlException (0x80131904): XML parsing: line 1, character 39, unable to switch the encoding

Upvotes: 0

Ben Asmussen
Ben Asmussen

Reputation: 994

Easy, define encoding in the output line:

%dw 1.0
%output application/xml encoding="utf-8"
---
name: payload.name?

the result:

<?xml version='1.0' encoding='utf-8'?>
<name>false</name>

Upvotes: 2

JoostD
JoostD

Reputation: 744

Go to your Anypoint Studio folder.

Edit AnypointStudio.ini

Add: -Dfile.encoding=UTF-8

Restart

Upvotes: 7

Related Questions