Monday, April 10, 2017

AX 2012: Reading XML Nodes through X++

XML to read

X++ Code

XmlDocument     doc;
XmlNodeList     xmlScriptList;
XmlNodeList     xmlResponseList;
XmlNodeList     xmlTemplateList;
XmlElement      nodeScript;
XmlElement      nodeResponse;
XmlElement      nodeTemplate;
XMLParseError   xmlError;
str xmlMsg;
int i, j;
// Create the XML Document
doc = new XmlDocument();
// 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()));

No comments:

Post a Comment

I will appreciate your comments !

Download large bacpac (sandbox database) to DEV environment much faster

As the LCS website gets slower and slower and the database backups get bigger and bigger.  Use AZCopy to download objects out of LCS asset l...