Add XML Version and Soap:Body to XML Dom Doc

AR-11AR-11 Member Posts: 5
Hi! I am trying to create a simple XML file to test with a 3rd party product. I am running into two issues that I can't seem to resolve. I have read through so many forums and can't seem to find the answers.

1. When I create my XML file, the 'version="1.0" encoding="UTF-8"' is only exporting the Version=1.0. The Encoding is not showing in my file. I am currently using the DomDoc CreateProcessingInstruction

2. I can't get the Node "Soap:Body" to print no matter what I try. I don't have it anywhere in my code at this time because no matter what I tried, it did't work.

I am all new to XML coding so hopefully this is something simple to some of you out there.

Here is my code:
IF ISCLEAR(XMLDOMDocument) THEN
  CREATE(XMLDOMDocument);
IF ISCLEAR(XMLDocOut) THEN
  CREATE(XMLDocOut);

DocNameSpace := '';

SoapEnvelope := '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope"/>';

XMLDomDocInst := XMLDOMDocument.createProcessingInstruction('xml','version="1.0" encoding="UTF-8"');
CurrNode := XMLDOMDocument.appendChild(XMLDomDocInst);
XMLDOMDocument.loadXML := (SoapEnvelope);
CurrNode := XMLDOMDocument.documentElement;

AddElement(CurrNode,'testPing', 'xmlns="http://xxx"',DocNameSpace,NewChild);
CurrNode := NewChild;

AddElement(CurrNode,'apiKey','API_KEY_VALUE,DocNameSpace,NewChild);
CurrNode := CurrNode.parentNode;


XMLDOMDocument.save('C:\XMLBuffer\TEST.xml');

If anyone can help it will be greatly appreciated!
Thank you!

Comments

  • GoMaDGoMaD Member Posts: 313
    1. look at codeunit 680 "Style Sheet Management", more precise at function ConvertMailMergeToStyleSheet
    2. a complete sample which works:
    PROCEDURE fct_CreateSOAPEnveloppe@1100095001(VAR pautXMLDom@1100095000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v4.0'.DOMDocument";ptxtFunction@1100095001 : Text[1024];VAR pautXMLFunctionNode@1100095005 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMNode";VAR pautXMLLoginNode@1100084000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMNode");
        VAR
          lautsoapEnvelope@1100095004 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMElement";
          lautsoapBody@1100095003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMElement";
          lautsoapMethod@1100095002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMElement";
          lautsoapInclReg@1100095007 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMElement";
          lautProcessingInstruction@1100084001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF89-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMProcessingInstruction";
          lautAttribute@1100084002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF85-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMAttribute";
          lautNode@1100084003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMNode";
        BEGIN
          //----------------------------------------------------------------------------------------------------------------------------------
          // Create SOAP Envelope
          //----------------------------------------------------------------------------------------------------------------------------------
          CLEAR(lautsoapEnvelope);
          lautsoapEnvelope := pautXMLDom.createElement('Soap:Envelope');
          lautsoapEnvelope.setAttribute('xmlns:Soap', 'http://schemas.xmlsoap.org/soap/envelope/');
          lautsoapEnvelope.setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
          lautsoapEnvelope.setAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
          pautXMLDom.appendChild(lautsoapEnvelope);
    
          //----------------------------------------------------------------------------------------------------------------------------------
          // Create SOAP Body
          //----------------------------------------------------------------------------------------------------------------------------------
          CLEAR(lautsoapBody);
          lautsoapBody := pautXMLDom.createElement('Soap:Body');
          lautsoapEnvelope.appendChild(lautsoapBody);
    
          //----------------------------------------------------------------------------------------------------------------------------------
          // Create Method Element
          //----------------------------------------------------------------------------------------------------------------------------------
          CLEAR(lautsoapMethod);
          lautsoapMethod := pautXMLDom.createElement(ptxtFunction);
          lautsoapMethod.setAttribute('xmlns', 'http://transics.org');
          lautsoapBody.appendChild(lautsoapMethod);
    
          //----------------------------------------------------------------------------------------------------------------------------------
          // Add login and Function node
          //----------------------------------------------------------------------------------------------------------------------------------
          lautsoapMethod.appendChild(pautXMLLoginNode);
    
          lautsoapMethod.appendChild(pautXMLFunctionNode);
    
          IF ptxtFunction = 'Get_ActivityReport_V5' THEN BEGIN
            lautsoapInclReg := pautXMLDom.createElement('IncludeRegistrations');
            lautsoapInclReg.text := 'true';
            lautsoapMethod.appendChild(lautsoapInclReg);
          END;
    
          lautNode := pautXMLDom.firstChild;
    
          lautProcessingInstruction := pautXMLDom.createProcessingInstruction('xml','version="1.0"');
          lautAttribute := pautXMLDom.createAttribute('encoding');
          lautAttribute.value := 'UTF-8';
          lautProcessingInstruction.attributes.setNamedItem(lautAttribute);
          pautXMLDom.insertBefore(lautProcessingInstruction,lautNode);
        END;
    
    Now, let's see what we can see.
    ...
    Everybody on-line.
    ...
    Looking good!
Sign In or Register to comment.