AX Data Export in XML file


static void XMLExport(Args _args)
{
    XmlDocument doc;
    XmlElement  nodeXml;
    XmlElement  nodeTable;
    XmlElement  nodeAccount;
    XmlElement  nodeName;
     XmlElement  nodeItemName;
    XmlElement  nodeModelGroup;
    XmlElement  nodeDimGroup;
    InventTable inventTable;
    #define.filename(‘C:\\Users\\varun.garg\\Desktop\\test.xml’)
    ;
    doc     = XmlDocument::newBlank();
    nodeXml = doc.createElement(‘xml’);
        doc.appendChild(nodeXml);
    while select inventTable
    {
        nodeTable = doc.createElement(tablestr(InventTable));
        nodeTable.setAttribute(
            fieldstr(InventTable, RecId),
            int642str(inventTable.RecId));
        nodeXml.appendChild(nodeTable);
        nodeAccount = doc.createElement(
            fieldstr(InventTable, ItemId));
        nodeAccount.appendChild(
            doc.createTextNode(inventTable.ItemId));
        nodeTable.appendChild(nodeAccount);
        nodeName = doc.createElement(
            fieldstr(InventTable, ItemGroupId));
        nodeName.appendChild(
            doc.createTextNode(inventTable.ItemGroupId));
        nodeTable.appendChild(nodeName);
         nodeItemName = doc.createElement(
            fieldstr(InventTable, ItemName));
        nodeItemName.appendChild(
            doc.createTextNode(inventTable.itemName));
        nodeTable.appendChild(nodeItemName);
        nodeModelGroup = doc.createElement(
            fieldstr(InventTable, ModelGroupId));
        nodeModelGroup.appendChild(
            doc.createTextNode(inventTable.ModelGroupId));
        nodeTable.appendChild(nodeModelGroup);
        nodeDimGroup = doc.createElement(
            fieldstr(InventTable, DimGroupId));
        nodeDimGroup.appendChild(
            doc.createTextNode(inventTable.DimGroupId));
        nodeTable.appendChild(nodeDimGroup);
    }
    doc.save(#filename);
}