
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);