AX / D365Fo – Add XSI:TYPE attribute in XML files – X++ #ax #msdyn365fo #d365fo

We want to create an XML file with :

  • a namespace in the first element.
  • an XSI prefix for XML elements attributes

Desidered output

<?xml version="1.0" encoding="UTF-8"?>

<FirstElement xmlns:xsi="">
<SecondElement xsi:type="Attribute"/>
class temp
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
        FileIoPermission permission;
        XMLDocument xmlDoc = XMLDocument::newBlank();
        XMLNode rootNode;
        XMLNode NodeEmpl;
        XMLElement xmlElement;
        str ns = '';

        permission= new FileIoPermission('C:\\Altitudo\\Test.xml','w');
        xmlDoc = XMLDocument::newBlank();

        // Create first node with namespace attribute and xsi
        rootNode = xmlDoc.documentElement();
        xmlElement = xmlDoc.createElement('FirstElement');
        rootNode = xmlDoc.appendChild(xmlElement);

        //Create a sub-node for the "xsi:type" attribute
        xmlElement = xmlDoc.createElement('SecondElement');
        xmlElement.setAttribute2('type', ns, 'Attribute');
        NodeEmpl = rootNode.appendChild(xmlElement);

        // Save the file'C:\\Altitudo\\test.xml');



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s