Reg. special characters in an XML file

In one of my flows to get an XML string output, I’m using documentToXMLString with encode = true. The resulting string has the special characters correctly encoded for eg. > < likewise. The XML also contains some other language characters as well which appear as some junk characters. The requirement here is to get an XML string with ‘?’ replaced over the special and the other language characters.How do I achieve this? Encoding is not specified anywhere, it just takes the system default value. Will this be achieved by mentioning a specific encoding?

Examples:

Actual output - Attached is a "docx file" as one example

Expected output - Attached is a ?docx file? as one example

Actual output - as in this case it doesn’t solve it.

Expected output - as in this case it doesn?t solve it.

Actual output - ¿formatAndExportToMedia¿.

Expected output - ?formatAndExportToMedia?

Actual output - we¿re quite sure it¿s

Expected output - we?re quite sure it?s

if you only support ASCII characters, you can call these two services in sequence, assuming you have a String variable that contains the xml string:
pub.string:stringToBytes
pub.string:bytesToString
For both, set encoding= ASCII
any character that’s not supported by ASCII will be replaced by ?

For more specific filtering, you also use regex with
pub.string:replace

Is your source from your pipeline document (IDATA) mapped structure received from your back end or else where?

Yes you can do the converting those lang data using steps above but assuming your IS handling or installed any other language packs?

Also try to force/set the charset to ISO-8859-1 and see how the xml string conversion would look like.

HTH,
RMG

Thank you for your suggestion Tong Wang. I tried as mentioned by you. It turned out that the other language and junk characters are getting replaced by ?? as expected but the spl characters ; ’ < > " etc are appearing as is, in both cases when XML encode is true and false. I will check if this is acceptable though. @RMG: Thank you for the response, I have tried the encoding already, it made no difference.