Friday, January 30, 2009

XML Export in Axapta [Simple Code]

static void RAJ_XMLWrite(Args _args)
{
XMLDocument xmlDoc = XMLDocument::newBlank();
XMLNode rootNode;
XMLNode NodeEmpl, NodeName, NodeAddr;
XMLElement xmlElement;
XMLText xmlText;
CustTable custTable;
int i;
;
// Create first line containing version info
rootNode = xmlDoc.documentElement();
xmlElement = xmlDoc.createElement("CustTable");
rootNode = xmlDoc.appendChild(xmlElement);
while select custTable order by recId
{
// Create a node for the CustTable record
xmlElement = xmlDoc.createElement("Customer");
NodeEmpl = rootNode.appendChild(xmlElement);
// Create a node for the name
xmlElement = xmlDoc.createElement("CustomerId");
NodeName = NodeEmpl.appendChild(xmlElement);
xmlText = xmlDoc.createTextNode(custTable.AccountNum);
NodeName.appendChild(xmlText);
// Create a node for the Name
xmlElement = xmlDoc.createElement("CustName");
NodeAddr = NodeEmpl.appendChild(xmlElement);
xmlText = xmlDoc.createTextNode(custTable.Name);
NodeAddr.appendChild(xmlText);
i++;
print i;
}
// Save the file
xmldoc.save('e:\\CustTable_XML.xml');
}

No comments: