AX - Create an XML file in X++ containing employee details

Create an XML file in X++ containing employee details

static void ShyamXMLWriteEmplAddr(Args _args)
{
FileIoPermission permission;
XMLDocument xmlDoc = XMLDocument::newBlank();
XMLNode rootNode;
XMLNode NodeEmpl, NodeName, NodeAddr;
XMLElement xmlElement;
XMLText xmlText;
HCMWorker HCMWorker;
;
permission= new
FileIoPermission('"C:\\Users\\shyamsundar.kanna\\Documents\\Testing\\Empl_Details_List.xml','w');
permission.assert();
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());
NodeName.appendChild(xmlText);
 
// Create a node for the address
xmlElement = xmlDoc.createElement('EmplEmail');
NodeAddr = NodeEmpl.appendChild(xmlElement);
xmlText =xmlDoc.createTextNode(HCMWorker.email());
NodeAddr.appendChild(xmlText);
}

// Save the file
xmldoc.save('C:\\Users\\shyamsundar.kanna\\Documents\\Testing\\Empl_Details_List.xml');
}

Comments