Home > X++ stuffs > Reading Selected Node in XML – Dynamics AX2012

Reading Selected Node in XML – Dynamics AX2012


Case Study: Below a sample job is illustrated to read selected (multiple) nodes from a given XML.


private static void SR_ReadSelectedNode_XML(Filename fileName)
{
    #define.node('INFORMATION//ROWS/ROW')
    XmlDocument xmlDocument;
    XmlNode     xmlInformationNode;
    XmlNodeList xmlInformationsNodeList;
    XmlNodeList xmlChildNodeList;
    int         i;
    int         j;

    fileName                = @'C:\Projects\ReadNode.xml';
    xmlDocument             = xmlDocument::newFile(fileName);
    xmlInformationsNodeList = xmlDocument.documentElement()
                                         .selectNodes(#node);
    
    setPrefix("@SYS98689");

    for ( i = 0; i < xmlInformationsNodeList.length(); i++)
    {
        xmlChildNodeList = xmlInformationsNodeList.item(i)
                                                  .childNodes();
        
        for (j = 0; j < xmlChildNodeList.length() ; j++) 
        {
            xmlInformationNode = xmlChildNodeList.item(j);

            if (xmlInformationNode.baseName() == 'DETAILS')
            {
                info(xmlInformationNode.innerXml());
                break;
            }
        }        
    }
}


Happy dAX(ml)ING 🙂 😛

Categories: X++ stuffs
  1. January 7, 2016 at 11:35 pm

    Goos aproach, however you should use a XmlNodeListIterator instead of a FOR loop.

    Cheers.

  2. July 23, 2015 at 3:31 am

    Do you have anything which reads HTML file ?

  3. August 25, 2012 at 6:54 pm

    good one. You can also use “Xpath” to create more standardized implementations and more flexible searchs http://www.w3schools.com/xpath/default.asp

  1. No trackbacks yet.

Leave a comment