BinaryFile in XML Tag

HelGonHelGon Member Posts: 10
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

  • jlandeenjlandeen Member Posts: 524
    Have you run this with debugger on? Which line of code does it abort your execution on?

    What size is the
    texto
    variable?

    One other possible problem I see here is that you have
    ChildNode3.text + texto
    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
    ChildNode3.text
    property and just copy the streams?
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • niscoxniscox Member Posts: 15
    The IXMLDOMText interface gives you functions for inserting text in chunks. Have a look at http://msdn.microsoft.com/en-us/library/ms757862(VS.85).aspx .
  • HelGonHelGon Member Posts: 10
    Thanks a lot.

    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;
  • jlandeenjlandeen Member Posts: 524
    Yeah I was wondering about that line of code...something like that would probably work fine in .Net but not quite in C/AL. That actually looks like a fairly simple solution and uses the base automation components, thanks for sharing that could come in handy!
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
Sign In or Register to comment.