Kbase P123034: Binary data is truncated in an XML file?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  26/03/2007 |
|
Status: Unverified
SYMPTOM(s):
Binary data is truncated in an XML file?
Creating XML files with binary data truncates the data.
CAUSE:
The binary data needs to be base64 encoded in order to be embedded into an XML file.
FIX:
Use the base64-Encode and base64-Decode functions in order to embed a binary file in XML.
For example:
DEFINE VARIABLE hField AS HANDLE.
DEFINE VARIABLE hText AS HANDLE.
DEFINE VARIABLE hBuf AS HANDLE.
DEFINE VARIABLE hDBFld AS HANDLE.
DEFINE VARIABLE i AS INTEGER.
DEF VAR msiFile AS LONGCHAR.
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
CREATE X-NODEREF hRow.
CREATE X-NODEREF hField.
CREATE X-NODEREF hText.
/* Copy binary file to memory pointer */
COPY-LOB FROM FILE 'J:\MobAMi.msi' TO mData.
/* Base 64 encode the data */
msiFile = BASE64-ENCODE(mData).
COPY-LOB FROM msiFile TO mb64Data.
/* Create XML File */
/*set up a root node*/
hDoc:CREATE-NODE(hRoot,"ttBinary","ELEMENT").
hDoc:APPEND-CHILD(hRoot).
hDoc:CREATE-NODE(hField,"binaryFile","ELEMENT").
hRoot:APPEND-CHILD(hField).
hDoc:CREATE-NODE(hText,"","TEXT").
hField:APPEND-CHILD(hText).
hText:MEMPTR-TO-NODE-VALUE(mb64Data).
hDoc:SAVE("file","j:\xml-out.xml").
DELETE OBJECT hDoc.
DELETE OBJECT hRoot.
DELETE OBJECT hRow.
DELETE OBJECT hField.
DELETE OBJECT hText.