AX – D365FO – Create an XML file in X++

Reference article :

This example create an XML file in X++ containing employee details

static void XMLWriteEmplAddr(Args _args)
   FileIoPermission permission;
   XMLDocument xmlDoc = XMLDocument::newBlank();
   XMLNode rootNode;
   XMLNode NodeEmpl, NodeName, NodeAddr;
   XMLElement xmlElement;
   XMLText xmlText;
   HCMWorker HCMWorker;

   permission= new FileIoPermission('C:\\Altitudo\\Empl_Details_List.xml','w');
   xmlDoc = XMLDocument::newBlank();

   // Create first line containing version info
   rootNode = xmlDoc.documentElement();
   xmlElement = xmlDoc.createElement('EmployeeList');
   rootNode = xmlDoc.appendChild(xmlElement);

   while select HCMWorker

      // Create a node for the Employee record
      xmlElement = xmlDoc.createElement('Employee');
      NodeEmpl = rootNode.appendChild(xmlElement);
      // Create a node for the name
      xmlElement = xmlDoc.createElement('EmplName');
      NodeName = NodeEmpl.appendChild(xmlElement);
      xmlText =xmlDoc.createTextNode(HCMWorker.Name());
      // Create a node for the address
      xmlElement = xmlDoc.createElement('EmplEmail');
      NodeAddr = NodeEmpl.appendChild(xmlElement);
      xmlText =xmlDoc.createTextNode(;

   // Save the file'C:\\Altitudo\\Empl_Details_List.xml');


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s