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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Create simple XML file

(0) ShareShare
ReportReport
Posted on by

Hello guys,

I'm starting to learn how to create XML for D365. 

I got this tutorial, but it looks like it is for AX2012, And here is what I already did :

class My_SimpleXMLCreate
{
    /// 
    /// Runs the class with the specified arguments.
    /// 
    /// The specified arguments.
    public static void main(Args _args)
    {
        XmlDocument xdoc;
        XmlElement  xElement;
        XmlElement  xTable, xNodeAccount, xNodeName;
        MainAccount mainAccount;

        #define.filename(@'C:\Temp\accounts.xml');

        xdoc = XmlDocument::newBlank();
        xElement =xdoc.createElement('xml');
        xdoc.appendChild(xElement);

        while select RecId, mainAccountId, Name from mainAccount
        {
            xTable = xdoc.createElement(tableStr(MainAccount));
            xTable.setAttribute(fieldStr(MainAccount, RecId), int642Str(mainAccount.RecId));
            xElement.appendChild(xTable);
            
            xNodeAccount = xdoc.createElement(fieldStr(MainAccount, MainAccountId));
            xNodeAccount.appendChild(xdoc.createTextNode(MainAccount.MainAccountId));
            xTable.appendChild(xNodeAccount);
            
            xNodeName = xdoc.createElement(fieldStr(MainAccount, Name));
            xNodeName.appendChild(xdoc.createTextNode(mainAccount.Name));
            xTable.appendChild(xNodeName);
        }

        xdoc.save(#filename);
        Info(strFmt("File %1 created", #filename));


    }

}

So 1st of all, after Build, I have this error and red line on the function name (public static void main) 

Severity Code Description Project File Line Suppression State
Error A reference to 'Dynamics.AX.SourceDocumentationTypes, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is required to compile this module. MyPro2 (ISV) [Fleet Management K:\AosService\PackagesLocalDirectory\bin\XppSource\FleetManagement\AxClass_My_SimpleXMLCreate.xpp 7

2nd, is because now on the Cloud, I don't think it is 'cool' to save it in C:\Temp, what would be the preferred way now ?

Lastly, how to improve this code to be more suitable in D365 environment ?

Thanks.

I have the same question (0)
  • vinitgoyal2005 Profile Picture
    6,332 on at
    RE: Create simple XML file

    Hi WWwong,

    What is the requirement here? If you want to export the data from D 365FO in XML format, you can use Data entities or use Electronic reporting. Creating an XML file directly from code is probably the last option. you can check this thread for that community.dynamics.com/.../generate-xml

  • Community Member Profile Picture
    on at
    RE: Create simple XML file

    Hi Vinit,

    To be honest, I just want to learn how to create XML from D365.

    Based on your experience, is there a case whereby this XML creation through code is needed ? maybe put the XML string to a table then it will be used by other process. I'm not too sure how is the process, but I do believe sometime it's happened.

    Put into table is just my assumption on where it this XML goes instead of file, but for the real case, I have yet experienced. Probably you can share your experience on this.

    But anyway, the main point is to understand how to create that XML through code.

    Thanks,

  • vinitgoyal2005 Profile Picture
    6,332 on at
    RE: Create simple XML file

    Hi WWwong,

    I am working in dynamics for the last 10+ years now. I have hardly seen a requirement where you have to explicitly create an XML from code. Most of the scenarios that come can be fulfilled by Data management export. So I suggest you may skip this part of learning and maybe ask the specific question when the actual scenario will come.

  • Community Member Profile Picture
    on at
    RE: Create simple XML file

    Hi Vinit,

    Noted,

    But it's not harm to know what's the error all about, right ?

    Thanks,

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at
    RE: Create simple XML file

    Hi Wong,

    I agree with Vinit. Such requirements hardly come up.

    But just in case, this error means you have to update the model parameters to include "SourceDocumentTypes" package. Go to Dynamics 365 > Model management > Update model parameters. Choose the model (I think Fleet management in your case), and choose the required package from the next screen.

  • Verified answer
    vinitgoyal2005 Profile Picture
    6,332 on at
    RE: Create simple XML file

    Hi,

    Yes sure for error Gunjan has shared the answer. you need to update the model references.

    For 2nd question, you cannot use "C:\Temp" to save it. you will can use Azure storage/Sharepoint to store the file. You can create the file in MemoryStream and send the email . You can use Microsoft Power Automate (flow) to generate the file and print/store to azure/use for any further processing etc. There are many scenarios available.

    Hope this helps.

  • Suggested answer
    Sukrut Parab Profile Picture
    71,699 Moderator on at
    RE: Create simple XML file

    Hi WWwong  ,

    With electronic reporting in place , it is better to go with ER framework for creating xml. If it for learning purpose then you can try x++ code but again as you asked you have to save it through code in blod and then download, ER does everything for your.Take a look at this link to see how you can do that

  • Community Member Profile Picture
    on at
    RE: Create simple XML file

    Hi all,

    Thank you for all this advices. I will follow all the leads.

    Thanks again.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,167

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 617 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans