Tuesday, November 16, 2010

Reading an XML file in AX 2009

These days there are lot of requirements on Integration with other systems like in import data and export data. One of the means is XML .
Here is a small job to read an XML file in AX

static void ReadingXMLFile(Args _args)

{
         XMLDocument XMLdoc
                        = XMLDocument::newFile      (@"C:\Users\nikhil.pujar\Desktop\Items.xml");
         int i,CountItemtags;
         ;
         XMLdoc.load(XMLdoc.toString());
         info(XMLdoc.getElementsByTagName("number").item(0).text());
         info(XMLdoc.getElementsByTagName("name").item(1).toString());
         countItemTags = xmldoc.getElementsByTagName('number').length();
         info (strfmt('Number of tags with name Item - %1', countItemTags));
        for (i = 0 ; i < countItemTags; i++)
       {
                info ("Item number :" + xmldoc.getElementsByTagName('number').item(i).text());
                info ("Item Name :" + xmldoc.getElementsByTagName('name').item(i).text());
        }
}

No comments:

Post a Comment