AX 2012: Reading XML Nodes under specific tag through X++

AX 2012: Reading XML Nodes under specific tag through X++

MCP · Azure DevOpsYour delivery board, readable by an agentMCP · DataverseOne consent, and the data layer opensMCP · Dynamics 365 F&OConnecting F&O to an agent Microsoft hasn’t documented

XML to read




















X++ Code 

For above XML structure, I will read all nodes exist within each InstructorAPIModel node. The getElementsByTagName() method of XmlDocument class can be used which returns XmlNodeList which can then be iterated to get node's values.

X++
  XmlDocument doc = new XmlDocument();
XmlNodeList         apiModelList;
XmlNodeListIterator iterator;
XmlElement          apiModel;
XmlElement          firstName;
XmlElement          lastName;

doc.loadXml(_xmlMsg);

apiModelList = doc.getElementsByTagName('InstructorApiModel');
iterator= new XmlNodeListIterator(apiModelList);

while (iterator.moreValues())
{
    apiModel = iterator.value();
        
    firstName = apiModel.getNamedElement('FirstName');
    if (firstName)
    {
        info(strFmt("First Name: %1", firstName.text()));
    }
        
    lastName = apiModel.getNamedElement('LastName');
    if (lastName)
    {
        info(strFmt("Last Name: %1", lastName.text()));
    }

    iterator.nextValue();
}
Previous article← AX 2012: Reading XML Nodes through X++
Discussion

Ask a question or leave feedback

This is a review interaction. The WordPress version will store, thread and moderate comments.

Thanks — submitted for moderation in this review.
Search the whole site · Ctrl/⌘ + K