Kbase P116921: Sample code to write and a dynamic temp-table schema to and from an xsd document.
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  22/06/2006 |
|
Status: Unverified
GOAL:
Sample code to write and a dynamic temp-table schema to and from an xsd document.
GOAL:
Sample code to write a dynamic temp-table schema to an xsd document.
GOAL:
Sample code to read a dynamic temp-table schema from an xsd document.
GOAL:
How to use the WRITE-XMLSCHEMA() method?
GOAL:
How to use the READ-XMLSCHEMA() method?
FIX:
1. The following procedure uses the WRITE-XMLSCHEMA() method to extract the xml schema of a dynamic TEMP-TABLE. To run this code, the sports2000 database must be connected:
/* WriteDynamicTempTableSchema.p */
DEFINE VARIABLE cTargetType AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE cEncoding AS CHARACTER NO-UNDO.
DEFINE VARIABLE lFormatted AS LOGICAL NO-UNDO.
DEFINE VARIABLE lMinSchema AS LOGICAL NO-UNDO.
DEFINE VARIABLE httCust AS HANDLE NO-UNDO.
DEFINE VARIABLE retOK AS LOGICAL NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
CREATE TEMP-TABLE httCust.
httCust:CREATE-LIKE("Customer").
httCust:TEMP-TABLE-PREPARE("ttCust").
ASSIGN
cTargetType = "FILE"
cFile = "ttCust.xsd"
lFormatted = YES
cEncoding = ?
lMinSchema = NO.
retOK= httCust:WRITE-XMLSCHEMA(cTargetType, cFile, lFormatted,
cEncoding, lMinSchema).
IF NOT retOK THEN
DO:
MESSAGE "READ-XML from " cFile " FAILED!!!" VIEW-AS ALERT-BOX.
DO iCounter = 1 TO ERROR-STATUS:NUM-MESSAGES:
MESSAGE iCounter ERROR-STATUS:GET-MESSAGE(iCounter) VIEW-AS ALERT-BOX.
END.
END.
ELSE
MESSAGE "XML data extracted successfully!"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
DELETE OBJECT httCust.
2. The following procedure uses the READ-XMLSCHEMA() method to creates a dynamic temp-table from the XML Schema document file ttCust.xsd that was generated by the code of the WriteDynamicTempTableSchema.p procedure above. This code may be run with or without a database connection:
/* ReadDynamicTempTableSchema.p */
DEFINE VARIABLE cSourceType AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE lOverrideDefaultMapping AS LOGICAL NO-UNDO.
DEFINE VARIABLE cFieldTypeMapping AS CHARACTER NO-UNDO.
DEFINE VARIABLE cVerifySchemaMode AS CHARACTER NO-UNDO.
DEFINE VARIABLE httCust AS HANDLE NO-UNDO.
DEFINE VARIABLE retOK AS LOGICAL NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
CREATE TEMP-TABLE httCust.
ASSIGN
cSourceType = "FILE"
cFile = "ttCust.xsd"
lOverrideDefaultMapping = ?
cFieldTypeMapping = ?
cVerifySchemaMode = ?.
retOK = httCust:READ-XMLSCHEMA(cSourceType, cFile, lOverrideDefaultMapping, cFieldTypeMapping, cVerifySchemaMode).
IF NOT retOK THEN
DO:
MESSAGE "READ-XML from " cFile " FAILED!!!" VIEW-AS ALERT-BOX.
DO iCounter = 1 TO ERROR-STATUS:NUM-MESSAGES:
MESSAGE iCounter ERROR-STATUS:GET-MESSAGE(iCounter) VIEW-AS ALERT-BOX.
END.
END.
ELSE
MESSAGE
"XML data extracted successfully!" "~n"
"There are " httCust:DEFAULT-BUFFER-HANDLE:NUM-FIELDS " fields in this table buffer"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
DELETE OBJECT httCust.