web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

XmlDocument UTF-8 encoding without BOM (Byte Order Mark)

(0) ShareShare
ReportReport
Posted on by 400

AX 2012 R2 CU7

I am observing that the default output of an Xml document generated in AX is UTF-8 with BOM (Byte Order Mark).

The receiver of the xml file cannot (automatically) process the document because of the 3 BOM characters at the front of the xml file.

The xml file is created using XmlDocument::newBlank().

newBlank has an optional string parameter of encoding which is defaulted to 'utf-8'

How do I change the encoding to utf-8 without BOM?  Is there an xslt for default xml documents that can be changed?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,805 Most Valuable Professional on at

    XML with UTF-8 encoding and BOM is valid (according to XML specification), therefore what's invalid is the receiver. I suggest fixing what's broken.

    Although you can use a different encoding in XMLDocument, I don't think it allows omitting BOM. If you really wanted to do it, you would have to write XML by something else (e.g. System.Xml.XmlWriter + UTF8Encoding(false)). Or you could first generate the file and then remove the BOM.

  • Rick Hutchison Profile Picture
    400 on at

    I agree with the assessment that the receiver should be able to handle XML with and without BOM.  The receiver was not willing to make any code changes unfortunately.

    A successful alternative was created using TextIo.  Here is my solution:

    client static void saveXMLOnClient(XmlDocument _xmlDoc, Filename _filename)

    {

       TextIo textIo;

       #File

       ;

       if (_xmlDoc && _filename)

       {

           textIo = new TextIo(_filename, #IO_WRITE, 437);

           textIo.write(_xmlDoc.toString());

           // prior code which adds BOM characters at front of XML file.

           //_xmlDoc.save(_filename);

       }

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans