Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How to force encoding in XML to UTF-8?

Posted on by Microsoft Employee

I am trying to enforce encoding in the xml I am building in following way:

XmlWriterSettings xmlSetting = new XmlWriterSettings();
XmlWriter xmlWriter;
Str res;


xmlSetting.encoding ('UTF-8');
xmlWriter = XmlWriter::newXml(xmlSetting);
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement('root');
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
xmlWriter.flush();
res = xmlWriter.writeToString();
info(res);

But the result of this in my system is:

<?xml version="1.0" encoding="utf-16"?><root />

What is the proper way to force encoding to UTF-8 and is it possible

Documentation does not provides examples:
docs.microsoft.com/.../gg929065(v%3dax.60)

I am using AX2012R3

*This post is locked for comments

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans