AX / D365FO – Set custom XML Namespaces Attributes (xmlns, xsi, etc..)

Use setAttribute method() to add custom Namespace to an XML node like shown below

//Create XML Document
XMLDocument xmlDoc;
XMLNode     root;
XMLElement  element;

xmlDoc = XMLDocument::newBlank();

element = xmlDoc.createElement('Invoice');
element.setAttribute('xmlns',"urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
element.setAttribute('xmlns:cac',"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateCoomponents-2");
element.setAttribute('xmlns:cbc',"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
element.setAttribute('xmlns:ccts',"urn:un:unece:uncefact:documentation:2");
element.setAttribute('xmlns:ext',"urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
element.setAttribute('xmlns:qdt',"urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
element.setAttribute('xmlns:udt',"urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2");
element.setAttribute('xmlns:xsd',"http://www.w3.org/2001/XMLSchema");
element.setAttribute('xmlns:xsi',"http://www.w3.org/2001/XMLSchema-instance");
element.setAttribute('xsi:schemaLocation',"urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");

root = xmlDoc.appendChild(element);

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Connecting to %s