Hi,
I'm creating a xml file using XML DOM Management and I need to send a binary file in my tag txtFile.
I have a text file named MyTxtFile.txt.
In my code I convert this file in a bynary using encode Base64.
Every thing works fine if I put a few words in my MyTxtFile.txt, but When I put a lot of words in MyTxtFile.txt an error occur:
Microsoft Business Solutions-Navision
The length of the text string exceeds the size of the string buffer.
OK
Here my code:
//Creating my XML
IF ISCLEAR(XMLDom) THEN
CREATE (XMLDom);
XMLDom.loadXML ('<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="
http://schemas.xmlsoap.org/soap/envelope/"/>');
XMLRoot := XMLDom.documentElement;
AddAttribute(XMLRoot,'xmlns:xsi','
http://www.w3.org/2001/XMLSchema-instance');
AddAttribute(XMLRoot,'xmlns:xsd','
http://www.w3.org/2001/XMLSchema');
XMLRoot := XMLDom.documentElement;
AddElement (XMLRoot,'soap:Header','','
http://schemas.xmlsoap.org/soap/envelope/',ChildNode2);
AddElement (ChildNode2,'Valida','','',ChildNode3);
AddElement (ChildNode3,'Nome','XPTO','',ChildNode4);
AddElement (ChildNode3,'PassW','XPTO','',ChildNode4);
AddElement (XMLRoot,'soap:Body','','
http://schemas.xmlsoap.org/soap/envelope/',ChildNode2);
//In this tag I want to pass my BASE64
AddElement (ChildNode2,'txtFile','','',ChildNode3);
//Tansform my MyTxtFile.txt in BASE64
//This will be saved in MyBinFile.txt
Ficheiro.TEXTMODE(FALSE);
Ficheiro.WRITEMODE(FALSE);
Ficheiro.OPEN('C:\MyTxtFile.txt');
Ficheiro.CREATEINSTREAM(FicheiroTXT);
Ficheiro2.CREATE('c:\MyBinFile.txt');
Ficheiro2.CREATEOUTSTREAM(FicheiroBase64);
Base64EncodeStream(FicheiroTXT,FicheiroBase64);
Ficheiro2.TEXTMODE(FALSE);
Ficheiro2.OPEN('c:\MyBinFile.txt');
Ficheiro2.CREATEINSTREAM(auxFicheiroBase64);
//Here I Read my BASE64 File and put his content in txtFile TAG
WHILE NOT auxFicheiroBase64.EOS DO BEGIN
auxFicheiroBase64.READTEXT(texto,1024);
ChildNode3.text(ChildNode3.text + texto);
END;
XMLDom.save('c:\MyXML' + FORMAT(WORKDATE,0,'<day><Month><Year4>')+ '.xml');
Comments
What size is the variable?
One other possible problem I see here is that you have line of code where the text property of ChildNode3 may exceed the longest possible string length. But when Navision tries to interpret ChildNode3.text the 2nd or any other time through the loop it tries to dereference that property of type BStr Text into a regular Navision Text variable and it blows up. Could you try creating a stream reference to the property and just copy the streams?
Epimatic Corp.
http://www.epimatic.com
Here's the code i had to change
WHILE NOT auxFicheiroBase64.EOS DO BEGIN
auxFicheiroBase64.READTEXT(texto,1024);
//ChildNode3.text(ChildNode3.text + texto);
ChildNode2 := XMLDom.createTextNode(texto);
ChildNode3.insertBefore(ChildNode2,ChildNode2.firstChild);
END;
Epimatic Corp.
http://www.epimatic.com