Thursday 24 January 2013

Parsing XML in Dynamics Ax 2012:



 Today I will be sharing "How to parse XML in AX 2012 " . I have used  XPath for navigating through the elements and attributes in XML. By the use of XPath it becomes very easy to parse an XML for selected nodes only.

 
This was my XML and I have to fetch all the Ownership prefixes for Group node having name attribute set to "GFM" and within that only that team which has name attribute set  to "Public Sector SL1" . After fetching the values of Prefixes I have to insert all those values in a table of type (tempdb) .

Now , I will show how i achieved that..

That's how my project looks..


This is my simple Job that does that all for me..


I defined my XPath in a Macro (#node) and passed that (#node) to XmlGroupnameNodeList . Have a look at this XPath ('//Team[@name="Public Sector SL1"]/Ownership/@prefix') it looks for Team node any where in the document having its name attribute set to (@name="Public Sector SL1") and within that team node it looks for the values of Ownership prefixes (Ownership/@prefix) .

I believe it was helpful....