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)

Set encoding on xml file

(0) ShareShare
ReportReport
Posted on by 32

Hi,

In AX 2012 I try to create an XML file and I want to set the encoding but don’t get it to work.

This is the code I use:

static void Job31(Args _args)

{

 

    XmlDocument             xmlDoc;

    XMLWriter               xmlWriter;

    XmlWriterSettings       xmlWriterSettings;

    Filename                filename        =   strFmt( "\\temp\\%1.xml", "encodingtest_ISO-8859-1" );

   

    #define.encoding('ISO-8859-1');

   

    xmlDoc                  =   XmlDocument::newBlank();

    xmlWriterSettings       =   new XmlWriterSettings();

    xmlWriterSettings.encoding( #encoding );

   

    xmlWriter               =   XMLWriter::newFile( filename, xmlWriterSettings );

    xmlDoc.writeTo( xmlWriter );

    xmlWriter.close();

   

}

 

And this is the result:

<?xml version="1.0" encoding="utf-8"?>

 

Anyone knows how to get ‘ISO-8859-1’ as encoding?

 

Thanks

Gunnar

*This post is locked for comments

I have the same question (0)
  • enricoariel Profile Picture
    60 on at

    i revised the code for you, it seems to do what you need:

    static void Job31(Args _args)

    {

       XmlDocument             xmlDoc;

       XMLWriter               xmlWriter;

       XmlWriterSettings       xmlWriterSettings;

       XmlDeclaration          xmldecl;

       XmlElement              root;

       Filename                filename        =   strFmt( "\\temp\\%1.xml", "encodingtest_ISO-8859-1" );

       #define.encoding('ISO-8859-1');

       xmlDoc                  =   new XmlDocument();//XmlDocument::newBlank();

       xmlWriterSettings       =   new XmlWriterSettings();

       xmldecl = xmlDoc.CreateXmlDeclaration("1.0",#encoding,'');

       root = xmlDoc.documentElement();

       xmlDoc.insertBefore(xmldecl, root);

       //xmlWriterSettings.encoding( #encoding );

       xmlWriter               =   XMLWriter::newFile( filename, xmlWriterSettings );

       xmlDoc.writeTo( xmlWriter );

       xmlWriter.close();

    }

    to know more about encoding please check here

    docs.microsoft.com/.../system.xml.xmldeclaration.encoding

  • Gunnar Johansson Profile Picture
    32 on at

    Unfortunately, it doesn't work. I get 'UTF-8'.

  • enricoariel Profile Picture
    60 on at

    that is quite strange, try to create a new job and export to a new file name just for double check. it must work, ax here is using a standard c# object and this is how it works according to the documentation.

  • Gunnar Johansson Profile Picture
    32 on at

    Created a new job with a new file name.

    The same result. <?xml version="1.0" encoding="utf-8"?>

  • Verified answer
    Rustem Galiamov Profile Picture
    8,072 on at

    Hi!

    Try this:

    xmlDoc = XMLDocument::newBlank('windows-1251');

    Screenshot-2019_2D00_08_2D00_15-at-11.57.46.png

  • Gunnar Johansson Profile Picture
    32 on at

    Thank's.

    Now it works to change encoding.

  • Verified answer
    Rustem Galiamov Profile Picture
    8,072 on at

    You are welcome!

    Please, mark question as answered to close the thread.

    Thanks!

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
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans