How to Read Data from XML File

Today I will demonstrate you that how to read data from XML file in AX.

static void ReadXml(Args _args)
{
XmlDocument xmlDoc;
XmlElement xmlRoot;
XmlElement xmlField;
XmlElement xmlRecord;
XmlNodeList xmlRecordList;
XmlNodeList xmlFieldList;
CarTable carTable;
DictTable dTable = new DictTable(tablenum(CarTable));
int i, j, fieldId;
#CarsXmlTags
;
xmlDoc = new xmlDocument();
xmlDoc.load(@"c:\temp\cars.xml");
xmlRoot = xmlDoc.getNamedElement(#CarRootNode);
xmlRecordList = xmlRoot.childNodes();
for (i=0; i<xmlRecordList.length(); i++)
{
carTable.clear();
xmlRecord = xmlRecordList.item(i);
xmlFieldList = xmlRecord.childNodes();
for (j=0; j<xmlFieldList.length(); j++)
{
xmlField = xmlFieldList.item(j);
carTable.(dTable.fieldName2Id(xmlField.name())) = xmlField.innerText();
}
carTable.insert();
}
}

Comments