Empty Namespace in XML

Hi,

I hope it's ok to post that problem here, because it might be related to using MSXML, which seems the only way to properly handle XML in the classic client.
I found some old code to consume a web service with C/AL, but it doesn't work. I suppose due to changes between MSXML versions.

The relevant part looks like that:

CREATE(xmldoc,TRUE,TRUE); 
// Create SOAP Envelope 
soapEnvelope := xmldoc.createElement('Soap:Envelope');
soapEnvelope.setAttribute('xmlns:Soap', 'http://schemas.xmlsoap.org/soap/envelope/');
xmldoc.appendChild(soapEnvelope); 
// Create SOAP Body 
soapBody := xmldoc.createElement('Soap:Body');
soapEnvelope.appendChild(soapBody); 
// Create Method Element 
soapMethod := xmldoc.createElement(method); 
soapMethod.setAttribute('xmlns', nameSpace);
soapBody.appendChild(soapMethod); 

// Transfer parameters by loading them into a XML Document and move them 
CREATE(parametersXmlDoc,TRUE,TRUE); 
parametersXmlDoc.loadXML('<parameters>'+parameters+'</parameters>');
IF parametersXmlDoc.firstChild.hasChildNodes THEN 
BEGIN 
  WHILE parametersXmlDoc.firstChild.childNodes.length>0 DO 
  BEGIN 
    nodel := parametersXmlDoc.firstChild.firstChild;
    nodel := parametersXmlDoc.firstChild.removeChild(nodel);
    soapMethod.appendChild(nodel);
    soapMethod.appendChild(nodel);
  END; 
END; 

This produces an empty namespace in the "itemNo" node:
wm8008u1z5nv.png

It should look like this:
ll9ufi2ry5pq.png

I alread know that the key is to give the "nodel"-node the same namespace as the soapMethod, but I haven't found a way so far.

As you might have guessed, this is my first encounter with composing XML, so any help is appreciated.

Comments

  • txerifftxeriff Member Posts: 492
    Hi,

    I would suggest to use XMLport to import/export xml file from NAV. its easiest way.

  • AKAK Member Posts: 226
    Thanks, but I would like to avoid that. However, I managed to get it working:
    IF parameterXMLDoc.firstChild.hasChildNodes THEN
    BEGIN 
      WHILE parameterXMLDoc.firstChild.childNodes.length > 0 DO BEGIN
    
        NewNode := parameterXMLDoc2.createNode(1,parameterXMLDoc.firstChild.firstChild.nodeName,nameSpace);  //Parametername
        NewNode2 := parameterXMLDoc.firstChild.firstChild.firstChild;                                        //Parameterwert
        NewNode2 := NewNode.appendChild(NewNode2);
    
        soapMethod.appendChild(NewNode);
    
        deletedNode := parameterXMLDoc.firstChild.firstChild;
        deletedNode := parameterXMLDoc.firstChild.removeChild(deletedNode);
    
      END;
    END;
    
Sign In or Register to comment.