02 September 2011

Job to Create XML File from AX

Now You can create an xml file of the table using the following code

void CreateItemXML()
{

XmlDocument xmlDoc;
XmlElement nodeXml;
XmlElement nodeTable;
XmlElement nodeItem;
XmlElement nodeName;
XmlElement nodeGroup;
XmlElement nodeType;
InventTable inventTable;
#define.filename('e:\\item.xml')//Location of item xml file
;
xmlDoc = XmlDocument::newBlank();
nodeXml = xmlDoc.createElement('xml');
xmlDoc.appendChild(nodeXml);
//Creates xml for all the items which have the ItemGroupId "Television"
while select inventTable where inventTable.ItemGroupId == "Television"
{
nodeTable = xmlDoc.createElement(tablestr(InventTable));

//Add RecId as an attribute
nodeTable.setAttribute(fieldstr(InventTable, RecId),
int642str(inventTable.RecId));
nodeXml.appendChild(nodeTable);

//Add ItemId as a node
nodeItem = xmlDoc.createElement(fieldstr(InventTable, ItemId));
nodeItem.appendChild(xmlDoc.createTextNode(inventTable.ItemId));
nodeTable.appendChild(nodeItem);

//Add Item name as a node
nodeName = xmlDoc.createElement(fieldstr(InventTable, ItemName));
nodeName.appendChild(xmlDoc.createTextNode(inventTable.ItemName));
nodeTable.appendChild(nodeName);

//Add Item group as a node
nodeGroup = xmlDoc.createElement(fieldstr(InventTable, ItemGroupId));
nodeGroup.appendChild(xmlDoc.createTextNode(inventTable.ItemGroupId));
nodeTable.appendChild(nodeGroup);

//Add Item type as a node
nodeType = xmlDoc.createElement(fieldstr(InventTable, ItemType));
nodeType.appendChild(xmlDoc.createTextNode(strfmt("%1",inventTable.ItemType)));
nodeTable.appendChild(nodeType);
}
xmlDoc.save(#filename);
}

1 comment:

  1. Why doesent this code print melding xsi:schemalocation?

    It prints d1p1:schemalocation!

    permission.assert();
    xmlDoc = new XMLDocument();
    xmlRoot = xmldoc.CreateElement("Root");
    xmlRoot = xmlDoc.documentElement();
    xmlpi = xmlDoc.createProcessingInstruction('xml', 'version=\"1.0\" encoding=\"utf-8\"');
    xmlDoc.appendChild(XMLpi);
    xmlMelding = xmlDoc.createElement('melding');
    xmlMelding.setAttribute2('schemaLocation','http://www.w3.org/2001/XMLSchema-instance', 'urn:ske:fastsetting:innsamling:saldoRente:2.0 saldoRente:2.0.xsd');
    xmlMelding.setAttribute('xmlns', 'http://www.w3.org/2001/XMLSchema-instance');
    xmlMelding.setAttribute('xmlns', 'urn:ske:fastsetting:innsamling:saldoRente:2.0');
    xmlLeveranse = xmlDoc.createElement('Leveranse');

    ReplyDelete

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...