Quantcast
Channel: Microsoft Dynamics 365 and Power Platform Library
Viewing all articles
Browse latest Browse all 102

AX 2012: Reading XML Nodes through X++

$
0
0

XML to read

















X++ Code








       XmlDocument    
doc;


    XmlNodeList     xmlScriptList;


    XmlNodeList     xmlResponseList;


    XmlNodeList     xmlTemplateList;




    XmlElement      nodeScript;


    XmlElement      nodeResponse;


    XmlElement      nodeTemplate;




    XMLParseError   xmlError;




    // Define
temporary variables


    str
_xmlMsg;


    int
i, j;


    ;


   


    // Create the
XML Document


    doc = new
XmlDocument();


    doc.loadXml(_xmlMsg);








    // Verify XML
Document Structure


    xmlError 
= doc.parseError();





    if(xmlError
&& xmlError.errorCode() != 0)


    {


        throw
error(strFmt("XML Error: %1", xmlError.reason()));


    }








    // Get the
root element and its child nodes


    nodeScript = doc.getNamedElement("ns2:return");


    xmlScriptList = nodeScript.childNodes();








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


    {


        nodeResponse = xmlScriptList.item(i);


        xmlResponseList =
nodeResponse.childNodes();




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


        {


            nodeTemplate =
xmlResponseList.item(j);


            xmlTemplateList =
nodeTemplate.childNodes();















            if
(nodeTemplate.selectSingleNode('id'))


            {


                info(strFmt("ID: %1",
nodeTemplate.getNamedElement("id").text()));


            }












            

           if
(nodeTemplate.selectSingleNode('messageTemplateName'))


           {




                info(strFmt("messageTemplateName:
%1"
, nodeTemplate.getNamedElement("messageTemplateName").text()));


           }




        }


    }









Viewing all articles
Browse latest Browse all 102

Trending Articles