Problem reading a XML with namespace

Hi everyone,

I’m connecting my NAV to a webService, it’s not my frist time, but it’s the first time that the received XML file as namespaces. This is how the XML to read look like:

I need to read the “faultstring” node.

I’ve tried to read it with the tipical “FindNodeText” function, but of course, the namespace provokes an error. So, as I’ve read in some articles, I am using the NamesPace manager, like this:

XMLDocDotNet := XMLDocDotNet.XmlDocument;
XMLDocDotNet.Load('C:\XML\XXXX\Login\login.xml');
// 
// 
  IF ISCLEAR(XMLHTTP) THEN
   CREATE(XMLHTTP,FALSE,TRUE);
XMLHTTP.open('POST', 'http://wstest.envialia.com:9085/soap/LoginCli');
XMLHTTP.setRequestHeader('Content-Type: ', 'application/x-www-form-urlencoded');
XMLHTTP.setRequestHeader('Host','XXXX.com:9085/soap');
XMLHTTP.setRequestHeader('SOAPAction', 'http://XXXX.com:9085/soap/LoginCli');
 
SLEEP(1000);
XMLText := XMLDocDotNet.OuterXml;
SLEEP(1000);
XMLHTTP.send(XMLText);

 IF ISCLEAR(locautXmlDoc) THEN
  CREATE(locautXmlDoc,FALSE,TRUE);

response := XMLHTTP.responseText;
LoadXMLDocumentFromText(response, locautXmlDocNet);
nms.AddNamespace('soap-ENV', 'http://schemas.xmlsoap.org/soap/envelope');
errorCode := FindNodeText(locautXmlDocNet,'@soap-ENV:Body/@soap-ENV:Fault/faultstring');

And here, I get this error:

envialia.png

"An instance of the dotnet variable hasn’t been created. Trying to call to system… "

I know this could be a problem with the DotNet variable. I’ve changed “RunOnClient” property to YES, but same error. IS there a better way to read this XML? may be an XMLPort? Or am I doing something wrong?

Thank you very much

Somehow I got the Error Message but I will be happy it could be in English?

Check out this -

https://rockwithnav.wordpress.com/2016/03/29/remove-namespace-web-service-response-dotnet-variable/

Thanks for your answer. This is the error:

ingles.png

I’ve also found your link with your code, but I’m not really sure I’ve understoood it…

Maybe this small function will help you out:

PROCEDURE RemoveNAMESPACE@1101107000();
VAR
NamespaceFound@1101107000 : Boolean;
ReadSize@1101107001 : Integer;
ReadCount@1101107002 : Integer;
FIleSize@1101107003 : Integer;
Pos@1101107004 : Integer;
ReadLine@1101107006 : Text[250];
BEGIN
// Remove Namespace attribute from XML-File, because it is not supported by NAV
NamespaceFound := FALSE;
ReadSize := 0;
ReadCount := 0;
XMLFile.TEXTMODE := TRUE;
TempServerFileName1 := FileManagement.UploadFileSilent(FileName);
XMLFile.OPEN(TempServerFileName1);
FIleSize := XMLFile.LEN;
REPEAT
ReadCount += 1;
ReadSize += (XMLFile.READ(ReadLine) + 2); // Bytes in record + 2 Byte CRLF
Pos := STRPOS(ReadLine,‘xmlns’); // Position of xmlns tag in record
IF Pos > 0 THEN
NamespaceFound := TRUE;
UNTIL (NamespaceFound = TRUE) OR // Stop reading, if namspace found
(ReadCount > 4) OR // Stop reading, if more than 4 records read
(ReadSize >= FIleSize); // Stop reading at end of file
XMLFile.CLOSE;
IF NamespaceFound THEN BEGIN
XMLFile.WRITEMODE := TRUE; // Reopen XML file in write mode and overwrite namespace
TempServerFileName1 := FileManagement.UploadFileSilent(FileName);
FileManagement.DeleteClientFile(FileName);
XMLFile.OPEN(TempServerFileName1);
XMLFile.SEEK(ReadSize - STRLEN(ReadLine) - 2 + Pos - 1); // position write pointer at ‘xmlns’
XMLFile.WRITE(PADSTR(’’,STRLEN(ReadLine) - (Pos -1) - 2) +’>’);
XMLFile.CLOSE;
FileManagement.DownloadToFile(TempServerFileName1,FileName);
END;
END;

Thanks, I’ll work on it!!

Thank you both for your tips. I’m working in both solutions, and I found problems.

[mention:0d5d5a12a38749cf82d5992cf1f92071:e9ed411860ed4f2ba0265705b8793d05], which are the parameters that the procedure receive? I n the load function, I have to write all the tags with namespace? The operning and closing ones?

[mention:3827a0b80bf644bf83619d3fe9e30125:e9ed411860ed4f2ba0265705b8793d05]. Thank you also for your function. I’m trying to adapt it to my development, but I’m finding a lots of problems with the object types and their methods. At least I’ve got and idea of how are you focusing the development.

Again thank you both, any hint will be welcome

Thank you both. I’ve solved the problem with the “GetElementsByTagName” function. I don’t know if it will work for all the processes, but at least I am advancing on my development.

Thank you!