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

Announcements

No record found.

News and Announcements icon
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
    239,419 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans