PreviousNextIndex

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: LOGICAL

Applies to: Buffer object handle, ProDataSet object handle, Temp-table object handle

Syntax
READ-XML ( source-type, { file | memptr | handle | longchar }, read-mode, 
schema-location, override-default-mapping [, field-type-mapping [, 
verify-schema-mode ] ] ) 

source-type
file
memptr
handle
longchar
read-mode
schema-location
override-default-mapping
field-type-mapping
field-name
data-type
verify-schema-mode

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: During the read operation, the AVM does not respond to ProDataSet events, and it does not track changes to the data in the ProDataSet or temp-table object (that is, it does not update the before-image tables) unless the XML document data is in the Microsoft DiffGram format.

You cannot read an XML document into a database buffer.

Note: When executing the READ-XML( ) method on a temp-table or ProDataSet, and the default buffer of one of the contained temp-tables is available, there is no guarantee as to the state of that buffer after the method finishes executing. The record buffer may not be available. If default buffer availability is an issue, it is suggested that a named buffer be used with this method. A named buffer can be created with the DEFINE BUFFER statement.

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: IS-XML attribute, READ-XMLSCHEMA( ) method, SERIALIZE-NAME attribute, WEB-CONTEXT system handle, WRITE-XML( ) method, WRITE-XMLSCHEMA( ) method, X-document object handle, X-noderef object handle, XML-NODE-NAME attribute


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex