Read XML file in AX

27 Dec

This post will not take your lots of time, just giving you one example to make you understand how can we read XML file. This post will enable you to read a file that is in the same format as the example in the previous post. You can try on your own to create a Job that reads an XML file that uses attributes such as the second example in the

previous post.


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;


// Create an XmlDocument object to hold the

// contents of the xml-file

xmlDoc = new XmlDocument();

// Load the content of the xml-file

// into the XmlDocument object


// Get the root node

xmlRoot = xmlDoc.getNamedElement(#CarRootNode);

// Get all child nodes (records)

xmlRecordList = xmlRoot.childNodes();

// Loop through the list of records

for (i=0; i<xmlRecordList.length(); i++)



// Get the current record from the

// record list

xmlRecord = xmlRecordList.item(i);

// Get all child nodes (fields)

xmlFieldList = xmlRecord.childNodes();

// Loop through the list of fields

for (j=0; j<xmlFieldList.length(); j++)


// Get the current field from the

// field list

xmlField = xmlFieldList.item(j);

// Set the matching field in the carTable

// to be equal to the inner text

// (the text between the tag and end tag).

carTable.(dTable.fieldName2Id( =



// Insert the record into the carTable




Leave a comment

Posted by on December 27, 2010 in AX, Basics, Dynamics, Tables, X++, XML


Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: