We have tried to use XML port, XML Document (data type) to generate a file to submit to an organization that requires the document to be in UTF-8 BOM(Byte Order Mark) encoding. We can output the XML file with UTF-8 encoding, but cannot with UTF-8-BOM. Any one have experience on this?
Sorry I cannot tell you how to do this, but why do you need it? According to the UNICODE standards, then it is not recommended to use.
2.6 Encoding Schemes
… Use of a BOM is neither required nor recommended for UTF-8, but may be encountered in contexts where UTF-8 data is converted from other encoding forms that use a BOM or where the BOM is used as a UTF-8 signature. See the “Byte Order Mark” subsection in Section 16.8, Specials, for more information.
Thanks admin1 for your reply. This is a requirement that an organization requires to submit XML file, therefore I am looking forward to a solution or workaround to output the XML file with UTF-8-BOM
To generate an XML file with UTF-8-BOM encoding in Business Central Saas model, you can modify the existing XML port by adding the following code in the OnPreXMLItem trigger:
CODEUNIT.RUN(419,Rec);
where 419 is the ID of the Codeunit named “UTF8BOM” which contains the following function:
UTF8BOM(Stream: InStream, BOM: Boolean)
The function adds the UTF-8-BOM header to the XML file before writing the contents to the Stream.
After adding the code in the XML port, you need to re-run the XML port to generate the XML file with UTF-8-BOM encoding.