Pierre
Pierre

Reputation: 61

How to make Mule 4, windows-1252 encoding, dataweave and NBSP character work?

I have an input payload that I cannot change the encoding (comes from a third party). It is as below:

<?xml version="1.0" encoding="window-1252"?>
<note>
<to>sample</to>
<from>testing</from>
<heading>dummy value</heading>
<body>stack overflow</body>
</note>

It is important to note that the spaces characters are not spaces, but Non-Break Spaces NBSP (0xa0). When I send this to my Mule 4 application and try to read the payload and change the encoding to UTF-8 (target system accepts UTF-8), it fails with the below error:

Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.

This is solved by removing the NBSP characters and replacing them by SPACES characters. But as mentioned before, I am not able to touch/change the incoming input. The issue is that I am unable to read this perfectly fine XML, as NBSP is part of the windows-1252 encoding. I tried to add a 'Set Payload' before the DW Transform Message processor and set the MIME Type to windows-1252, with a simple Set Payload code:

output application/xml encoding="UTF-8" --- payload

This does not work and the error is the same. How can I read NBSP characters in DW/Mule 4? Thanks.

Upvotes: 0

Views: 617

Answers (1)

aled
aled

Reputation: 25699

The problem is that your input XML has its XML declaration (<?xml version="1.0" encoding="window-1252"?>) line using the same character (0xA0) instead of spaces. I don't believe it is valid XML to use anything other than the standard space character between the elements of the XML declaration. So the issue is caused because the input is not valid XML. Same characters in the body doesn't cause the error.

If you need to process it anyway try to set the MIME type of the input to be text/plain, do string replacement of the characters for valid spaces and then read() it as XML.

Upvotes: 1

Related Questions