Consultor Eletrônico



Kbase P13570: How to read an XML document into a MEMPTR when the document is being read via INPUT THROUGH
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   04/04/2005
Status: Verified

GOAL:

How to read an XML document into a MEMPTR when the document is being read via INPUT THROUGH

FACT(s) (Environment):

Progress 9.x

FIX:


DEFINE VARIABLE mXMLDocument AS MEMPTR NO-UNDO.
DEFINE VARIABLE cNumBytes AS CHARACTER NO-UNDO.
DEFINE VARIABLE iOffset AS INTEGER NO-UNDO INITIAL 0.

INPUT THROUGH "CMD /C TYPE SomeDocument.XML".

/*---------------------------------------------------------------*/
/* Input data will contain the actual number of bytes in the XML */
/* document at the beginning of the file. This number (in plain */
/* ASCII format) will be terminated by a comma and the XML */
/* will begin immediately after that. */
/* */
/* The following REPEAT block reads the input stream, extracts */
/* the size information located at the beginning of the file and */
/* allocates the memory for the XML document. */
/*---------------------------------------------------------------*/

REPEAT:
READKEY PAUSE 0.
IF LASTKEY = -1 THEN
DO:
MESSAGE 'Unexpected End of Data' VIEW-AS ALERT-BOX.
INPUT CLOSE.
RETURN.
END.
ELSE
IF KEYLABEL(LASTKEY) = ',' THEN
DO:
SET-SIZE(mXMLDocument) = INTEGER(cNumBytes).
LEAVE.
END.
ELSE
ASSIGN cNumBytes = cNumBytes + KEYLABEL(LASTKEY).
END.

/*---------------------------------------------------------------*/
/* The following REPEAT block reads the actual data from the */
/* input stream and stores it in a MEMPTR variable. */
/*---------------------------------------------------------------*/

REPEAT:
READKEY PAUSE 0.
IF LASTKEY = -1 THEN
LEAVE.
ELSE
DO:
ASSIGN iOffset = iOffset + 1.
PUT-BYTE(mXMLDocument, iOffset) = LASTKEY.
END.
END.

/*---------------------------------------------------------------*/
/* The following code should be modified so that the data (which */
/* is now in a MEMPTR) is manipulated in whatever manner is */
/* required by the application. */
/*---------------------------------------------------------------*/

INPUT CLOSE.

MESSAGE GET-SIZE(mXMLDocument) VIEW-AS ALERT-BOX.

MESSAGE GET-STRING(mXMLDocument,1) VIEW-AS ALERT-BOX.

SET-SIZE(mXMLDocument) = 0.