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 :
Finance | Project Operations, Human Resources, ...
Answered

Export XML Encoding UTF-8 Without BOM

(2) ShareShare
ReportReport
Posted on by 89
Hi, I want to export XML with File Encoding "UTF-8"  but the encoding file always "UTF-8 With BOM", please give me solution to export XML with File Encoding "UTF-8".
 
public void writeXmlFile(XmlDocument _xmlDoc)
{
    using (var stream = new System.IO.MemoryStream())
    {
        XMLWriter writer = XMLWriter::newStream(stream); //Convert the Xml to a memory stream and pass it to use File::SendFileToUser method
        _xmlDoc.writeTo(writer);
        writer.flush();

        File::SendFileToUser(stream, 'XmlFile.xml');
    }
}
Categories:
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    You should be able to achieve that by using XmlWriterSettings with Encoding = new System.Text.UTF8Encoding(false).
     
    Unfortunately, the X++ class XmlWriterSettings doesn't support it; there you can provide the encoding name only, not additional parametes. But the class is actually just a wrapper of the .NET class, System.Xml.XmlWriterSettings, and you can provide the .NET object in it's constructor.
     
    Therefore I suggest the following:
    System.Xml.XmlWriterSettings netWriterSettings = new System.Xml.XmlWriterSettings();
    netWriterSettings.Encoding = new System.Text.UTF8Encoding(false);
    
    XmlWriterSettings axWriterSettings = new XmlWriterSettings(netWriterSettings);
    
    XMLWriter writer = XMLWriter::newStream(stream, axWriterSettings);
    Alternatively, you could ignore the X++ wrappers and use the .NET API directly.
  • AB-21051008-0 Profile Picture
    89 on at
    Thanks Sir, It's Works!!
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    That's good to hear.
    Please don't forget to verify the answer.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans