Previous Next

READ-XML( ) method
Reads an XML document into a ProDataSet, temp-table, or temp-table buffer object. You can read data, schema, or both.
Return type:
Applies to:
 
Syntax 
READ-XML ( source-type , { file | memptr | handle | longchar } , read-mode 
  , schema-location , override-default-mapping 
  [ , field-type-mapping [ , verify-schema-mode ] ] )
source-type
A CHARACTER expression that specifies the source XML document type. Valid values are "FILE", "MEMPTR", "HANDLE", and "LONGCHAR".
file
A CHARACTER expression that specifies the name of a file. You can specify an absolute pathname, a relative pathname (based on the current working directory), or a URL pathname. Valid URL protocols include FILE and HTTP (the HTTPS protocol is not supported). The AVM verifies that the file exists and is accessible The pathname can contain Unicode characters. See OpenEdge Development: Internationalizing Applications for more information about Unicode.
memptr
A MEMPTR variable that contains the XML document text in memory. The size of the MEMPTR variable must match the size of the XML document text.
handle
A WEB-CONTEXT system handle, X-document object handle, or X-noderef object handle.
For a WEB-CONTEXT system handle, the READ-XML( ) method reads an XML document from the WebSpeed transaction server. The method verifies that the XML document was posted to the WebSpeed transaction server (that is, the value of the IS-XML attribute for the handle is YES), and that ABL is running in a WebSpeed environment.
longchar
A LONGCHAR variable that contains the XML document text in memory.
read-mode
A CHARACTER expression that specifies the mode in which the READ-XML( ) method reads data from the XML document into a temp-table or ProDataSet member buffer. The expression must evaluate to "APPEND", "EMPTY", "MERGE", or "REPLACE". The default value is "MERGE".
Table 98 lists the READ-XML( ) method modes for reading data.
 
schema-location
A CHARACTER expression that specifies the name of an external XML Schema file to use in creating or verifying the object’s schema when reading in the XML document. You can specify an absolute pathname, a relative pathname (based on the current working directory), or a URL pathname. Valid URL protocols include FILE and HTTP (the HTTPS protocol is not supported). The AVM verifies that the file exists and is accessible. When specified, the AVM ignores any schema defined or referenced in the source XML Document. The pathname can contain Unicode characters.
If you specify the empty string ("") or the Unknown value (?), the AVM creates or verifies the object’s schema using any XML Schema defined or referenced in the XML document.
override-default-mapping
A LOGICAL expression where TRUE directs the AVM to override the default mapping between XML Schema string and binary data types and ABL data types when creating an ABL temp-table schema from an XML Schema. The default value is FALSE.
The XML Schema string data type maps to the ABL CHARACTER data type by default, and the XML Schema base64Binary and hexBinary data types map to the ABL RAW data type by default. If you specify TRUE, the READ-XML( ) method creates a temp-table schema with CLOB and BLOB fields instead of CHARACTER and RAW fields.
If you specify the Unknown value (?), the method uses the default value of FALSE.
field-type-mapping
An optional CHARACTER expression that evaluates to a comma-delimited list of field name, data type pairs using the following syntax:
 
Syntax 
"field-name-1,data-type-1[,field-name-n,data-type-n]..."
This option allows you to specify the ABL data type for a specific field from the XML Schema.
field-name
A CHARACTER expression that evaluates to the name of the specified field. For a ProDataSet object, you must qualify the field name with the buffer name from the XML Schema. That is, buffer-name.field-name.
data-type
A CHARACTER expression that evaluates to the data type of the specified field. The data type must be a valid ABL data type, and it must be compatible with the XML Schema type based on the ABL XML data type mapping rules. For example, any XML Schema type can be mapped to an ABL CHAR or CLOB, but an XML Schema dateTime can be mapped only to an ABL DATE, DATETIME or DATETIME-TZ.
If you specify the Unknown value (?), the method uses the default data type mapping. For more information about the ABL XML data type mapping rules, see OpenEdge Development: Working with XML.
verify-schema-mode
An optional CHARACTER expression that specifies the mode in which the READ-XML( ) method verifies any XML Schema against existing ABL schema. The expression must evaluate to "IGNORE", "LOOSE", or "STRICT". The default value is "LOOSE".
Note:
Table 99 lists the READ-XML( ) method schema verification modes.
 
Ignores any XML Schema specified in schema-location, or defined in the XML Document.
If you specify the Unknown value (?), the method uses the default value of LOOSE.
If the XML Schema verification fails, the method generates an error message indicating the XML Schema element that caused the failure and returns FALSE.
If the ProDataSet or temp-table object does not have a schema (that is, the object is dynamic and in the CLEAR state), the AVM creates the schema from either the XML Schema file specified in schema-location, or the XML Schema defined or referenced in the XML document. If a dynamic temp-table is not in the PREPARED or CLEAR state, the method generates an error and returns FALSE.
ABL has a pair of attributes with overlapping purposes in how the AVM reads XML data, SERIALIZE-NAME and XML-NODE-NAME. Refer to the attribute entries for a full description of their interaction.
If the ProDataSet or temp-table object already has a schema (that is, the object is static, or the temp-tables are in the PREPARED state), the AVM verifies any XML Schema specified by schema-location, or defined or referenced in the XML document, against the object’s schema, unless the verify-schema-mode is "IGNORE".
If the AVM cannot identify any XML Schema for the ProDataSet or temp-table object, (that is, schema-location is the empty string ("") or the Unknown value (?) and the XML document does not define or reference a schema, the AVM infers the schema from the data in the XML document.
For more information about creating schema from XML Schema, verifying XML Schema, or inferring schema from XML document text, see OpenEdge Development: Working with XML.
The XML document can also contain before-image table data associated with a ProDataSet object. If the XML document data is in the Microsoft DiffGram format, the method reads the before-image data as well. In this case, if the ProDataSet or temp-table object is static and it does not have a before-image table defined, the method generates an error and returns FALSE. If the ProDataSet or temp-table object is dynamic, the method creates the before-image table automatically.
Note:
You cannot read an XML document into a database buffer.
Note:
The following code example creates a dynamic ProDataSet object from an empty ProDataSet handle, creates the object’s schema from the specified XML Schema file, and populates the temp-tables with records from the specified XML document:
 
DEFINE VARIABLE cSourceType             AS CHARACTER NO-UNDO.
DEFINE VARIABLE cReadMode               AS CHARACTER NO-UNDO.
DEFINE VARIABLE lOverrideDefaultMapping AS LOGICAL   NO-UNDO.
DEFINE VARIABLE cFile                   AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSchemaLocation         AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFieldTypeMapping       AS CHARACTER NO-UNDO.
DEFINE VARIABLE cVerifySchemaMode       AS CHARACTER NO-UNDO.
DEFINE VARIABLE lRetOK                  AS LOGICAL   NO-UNDO.
DEFINE VARIABLE hDSet                   AS HANDLE    NO-UNDO.
 
CREATE DATASET hDSet.
ASSIGN
  cSourceType             = "file"
  cFile                   = "dset.xml" 
  cReadMode               = "empty"
  cSchemaLocation         = "cust-ord-inv.xsd"
  lOverrideDefaultMapping = ?
  cFieldTypeMapping       = ?
  cVerifySchemaMode       = ?.
 
lRetOK = hDSet:READ-XML(cSourceType, cFile, cReadMode, cSchemaLocation,
  lOverrideDefaultMapping, cFieldTypeMapping, cVerifySchemaMode).
The following code example creates a dynamic temp-table object from an empty temp-table handle, creates the object’s schema from the specified XML Schema file, and populates the temp-table with records from the specified XML document:
 
DEFINE VARIABLE cSourceType             AS CHARACTER NO-UNDO.
DEFINE VARIABLE cReadMode               AS CHARACTER NO-UNDO.
DEFINE VARIABLE lOverrideDefaultMapping AS LOGICAL   NO-UNDO.
DEFINE VARIABLE cFile                   AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSchemaLocation         AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFieldTypeMapping       AS CHARACTER NO-UNDO.
DEFINE VARIABLE cVerifySchemaMode       AS CHARACTER NO-UNDO.
DEFINE VARIABLE lRetOK                  AS LOGICAL   NO-UNDO.
DEFINE VARIABLE httCust                 AS HANDLE    NO-UNDO.
 
CREATE TEMP-TABLE httCust.
ASSIGN
  cSourceType             = "file"
  cFile                   = "ttcust.xml" 
  cReadMode               = "empty"
  cSchemaLocation         = "ttcust.xsd"
  lOverrideDefaultMapping = ?
  cFieldTypeMapping       = ?
  cVerifySchemaMode       = ?.
 
lRetOK = httCust:READ-XML(cSourceType, cFile, cReadMode, cSchemaLocation,
  lOverrideDefaultMapping, cFieldTypeMapping, cVerifySchemaMode).
See also:

Previous Next
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates.