Consultor Eletrônico



Kbase P107452: X-document SAVE method doesn't work for UTF-16 encoding when the destination is LONGCHAR
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   19/06/2009
Status: Verified

SYMPTOM(s):

X-document SAVE method doesn't work when the destination is LONGCHAR

WRITE-XML to LONGCHAR generates leading byte order mark in XML which doesn't translate to cpinternal

Could not convert LONGCHAR to cpinternal. (11669)

The XML has UTF-16 encoding

The SAVE operation apparently fails when trying to save the "?" character from the xml header: <?xml version ...

Works fine when saving to a file or MEMPTR instead of LONGCHAR variable

Works fine with UTF-8 encoding

Reproducible:
/*--------------------*/
DEFINE VARIABLE hXDoc AS HANDLE NO-UNDO.
DEFINE VARIABLE hXRoot AS HANDLE NO-UNDO.
DEFINE VARIABLE cXML AS LONGCHAR NO-UNDO.
DEFINE VARIABLE cTest AS CHARACTER NO-UNDO.
CREATE X-DOCUMENT hXDoc.
CREATE X-NODEREF hXRoot.
hXDoc:CREATE-NODE(hXRoot,"TestRootNode","ELEMENT").
hXDoc:APPEND-CHILD(hXRoot).
hXDoc:ENCODING = "utf-16".
hXDoc:SAVE ("longchar",cXML).
DELETE OBJECT hXDoc NO-ERROR.
DELETE OBJECT hXRoot NO-ERROR.
ASSIGN cTest = cXML.
MESSAGE cTest VIEW-AS ALERT-BOX.
/*-----------------------*/

FACT(s) (Environment):

All Supported Operating Systems
OpenEdge 10.0B
OpenEdge 10.1x

CAUSE:

Bug# 20050809-006

CAUSE:

Bug# OE001188238

FIX:

Use the X-document SAVE method to save the XML to a MEMPTR. Then copy from the MEMPTR to the LONGCHAR variable.
Below is a short example:
/*---------------------------*/
DEFINE VARIABLE hXDoc AS HANDLE NO-UNDO.
DEFINE VARIABLE hXRoot AS HANDLE NO-UNDO.
DEFINE VARIABLE cXML AS LONGCHAR NO-UNDO.
DEFINE VARIABLE mXML AS MEMPTR NO-UNDO.
DEFINE VARIABLE cTest AS CHARACTER NO-UNDO.
CREATE X-DOCUMENT hXDoc.
CREATE X-NODEREF hXRoot.
hXDoc:CREATE-NODE(hXRoot,"TestRoot","ELEMENT").
hXDoc:APPEND-CHILD(hXRoot).
hXDoc:ENCODING = "utf-16".
/*hXDoc:SAVE ("longchar",cXML).*/
hXDoc:SAVE("MEMPTR":U, mXML).
DELETE OBJECT hXDoc NO-ERROR.
DELETE OBJECT hXRoot NO-ERROR.
FIX-CODEPAGE(cXML) = "UTF-16".
COPY-LOB FROM mXML TO cXML NO-CONVERT. /* now the result is in a LONGCHAR variable*/
/* for display reasons will output to a file and open the file in OS*/
COPY-LOB FROM cXML TO FILE "aaa.xml" NO-CONVERT.
OS-COMMAND NO-WAIT "aaa.xml".
/*---------------------------*/