Dealing with class XmlService trying to build a XML SEPA file

56 views Asked by At

I want to build a XML file, in apps script with XmlService, but I am locked in the construct of first 2 lines . (an additional problem I have, is how to expose the facts in an understandable English. also I am not sure if it is correctly formatted according of stackoverflow rules. )

This are the first 2 lines of XML file I want to create

    <Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02">

I tried without success the following code with 3 different test alternatives and his corresponding errors (please comment the test-1, -2, and/or -3 to test) I included the error generated during each alternative execution :

function testXmlDocument() {
    var document = XmlService.createDocument();
    var root = XmlService.createElement('Root');
    document.setRootElement(root);
    
> test1
    var namespaceNode2 = XmlService.createElement('NamespaceNode2', 
                        'urn:iso:std:iso:20022:tech:xsd:pain.001.001.03');
> *Error Exception: The parameters (String,String) don't match the
                    method signature for XmlService.createElement.*
    root.addContent(namespaceNod2e);

 > test2
    var namespaceNode3 = XmlService.createElement('NamespaceNode3');
    root.addContent(namespaceNode3);
    namespaceNode3.setAttribute('xmlns', 
                        'urn:iso:std:iso:20022:tech:xsd:pain.001.001.03');
> *Error Exception: Unexpected error while getting the method or property 
                    setAttribute on object XmlService.Element.*

> test3
    var child1 = XmlService.createElement('child1');
    root.addContent(child1);
    child1.setAttribute('xmlns', 
                        'urn:iso:std:iso:20022:tech:xsd:pain.001.001.03');
> *Error Exception: Unexpected error while getting the method or property 
                     setAttribute on object XmlService.Element.*

> To check results : Convert the XML document to a string
    var xmlString = XmlService.getPrettyFormat().format(document);
    Logger.log(xmlString);
 }
0

There are 0 answers