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)

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

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans