Submitted by Anonymous (not verified) on Wed, 07/09/2014 - 00:00
Forums

Hi,

How do I handle Compresse XML tags in GZIPBase64Binary?

Niels Liisberg

Wed, 07/09/2014 - 00:00

Hi,

It is actually stored in the order it says. First data is compressed with G-ZIP and the binary converted to base64 so it can be consumed in a XML file.

Now – to convert that to its origin you have to do it in reverse order – and in IceBreak we are using ILOB’s (Internal Large Objects)

<%
// Example:
// xml base64 gzip decoding
// ------------------------------------------------------------------
H bnddir('ICEUTILITY' : 'QC2LE')

/include qasphdr,iceutility
/include qasphdr,ilob
/include qasphdr,xmlParser
/include qasphdr,ifs

var il2 ptr
var il1 ptr
var pXml ptr

/free
 *inlr = *ON;

  // First parse the XML
  pXml = xml_ParseFile('xmlbase64gzip.xml');

  // Now copy the node to an ilob
 il1 = SesGetILOB ('temp1');

 xml_GetIlobValue (il1 : pXml: (
         '/Envelope/Body/nfeDownloadNFResult' +
          '/retDownloadNFe/retNFe/procNFeGrupoZip/NFeZip'
 ));

 // Convert it from base 64 to binary
  il2 = SesGetILOB ('temp2');
 ILOB_Base64Decode (il2:il1);

  // save it to disk
  ILOB_SaveToBinaryStream ( il2: '/tmp/outtemp.xml.gz');

  // unzip it
 fileGunzip( '/tmp/outtemp.xml' : '/tmp/outtemp.xml.gz');


  // show the result:
 %><pre><%
 include ('/tmp/outtemp.xml');
 %></pre><%

  // clean up:
  unlink ('/tmp/outtemp.xml');
  unlink ('/tmp/outtemp.xml.gz');

 xml_close(pXml);

Note this requires ICEBREAK build 431 or above….

Best regards,
Niels Liisberg