PreviousNextIndex

WRITE-XML( ) method

Writes an XML document from a ProDataSet, temp-table, or temp-table buffer object. In the case of the temp-table buffer object, all the records of the temp-table associated with the buffer object are written to the XML document—not just the one in the buffer. You can write the XML representation of the object with data, schema, or both. If you include schema, it is written using the XML Schema Definition (XSD) language.

When writing data from a ProDataSet object, the AVM writes the current version of data in each row of each table in the ProDataSet object. However, you can also include any before-image data, so that both the current and original versions of the data in each table row are written.

When writing schema for a ProDataSet object, the AVM writes all table definitions as well as relation and index definitions. When writing schema for a temp-table or temp-table buffer object, the AVM writes only table and index definitions.

Return type: LOGICAL

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

Syntax
WRITE-XML ( mode, { file | stream | stream-handle | memptr | handle | 
longchar }[, formatted [, encoding [, schema-location [, write-xmlschema 
[, min-xmlschema [, write-before-image [, omit-initial-values ] ] ] ] ] 
] ] ) 

mode
file
stream
stream-handle
memptr
handle
longchar
formatted
encoding
schema-location
write-xmlschema
min-xmlschema
write-before-image
omit-initial-values

You can specify how a temp-table column is represented in XML (that is, as an ELEMENT, ATTRIBUTE, or TEXT) by:

When writing data from a ProDataSet object that contains data-relations, you can nest child rows of a ProDataSet buffer within their parent rows in the resulting XML document by:

ABL has pairs of attributes with overlapping purposes in how the AVM outputs XML data:

Refer to the attribute entries for a full description of their interaction.

If your temp-tables contain array fields, third party products utilizing the XML might not map the ABL array field to an array column or object. For best interoperability with third party products, flatten array fields into individual fields.

You cannot write an XML document from a database buffer.

Note: When executing the WRITE-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 defines a static ProDataSet object, attaches its data sources, fills the ProDataSet object, and writes the ProDataSet object to an XML document in a nested manner:

DEFINE VARIABLE cTargetType     AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cFile           AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lFormatted      AS LOGICAL   NO-UNDO. 
DEFINE VARIABLE cEncoding       AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cSchemaLocation AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lWriteSchema    AS LOGICAL   NO-UNDO. 
DEFINE VARIABLE lMinSchema      AS LOGICAL   NO-UNDO. 
DEFINE VARIABLE lRetOK          AS LOGICAL   NO-UNDO. 
DEFINE TEMP-TABLE ttCustomer NO-UNDO LIKE Customer. 
DEFINE TEMP-TABLE ttOrder    NO-UNDO LIKE Order. 
DEFINE TEMP-TABLE ttInvoice  NO-UNDO LIKE Invoice. 
DEFINE DATASET DSET FOR ttCustomer, ttOrder, ttInvoice 
  DATA-RELATION CustOrd FOR ttCustomer,  
    ttOrd RELATION-FIELDS(CustNum,CustNum) NESTED 
  DATA-RELATION OrdInv FOR ttOrder,  
    ttInv RELATION-FIELDS(OrderNum,OrderNum) NESTED. 
DEFINE DATA-SOURCE dsCustomer FOR Customer. 
DEFINE DATA-SOURCE dsOrder    FOR Order. 
DEFINE DATA-SOURCE dsInvoice  FOR Invoice. 
BUFFER ttCustomer:HANDLE:ATTACH-DATA-SOURCE(DATA-SOURCE dsCustomer:HANDLE). 
BUFFER ttOrder:HANDLE:ATTACH-DATA-SOURCE(DATA-SOURCE dsOrder:HANDLE). 
BUFFER ttInvoice:HANDLE:ATTACH-DATA-SOURCE(DATA-SOURCE dsInvoice:HANDLE). 
DATA-SOURCE dsCustomer:FILL-WHERE-STRING = "WHERE Customer.CustNum = 2 ". 
DATASET DSET:FILL(). 
ASSIGN 
  cTargetType     = "file" 
  cFile           = "dset.xml"  
  lFormatted      = TRUE 
  cEncoding       = ? 
  cSchemaLocation = ? 
  lWriteSchema    = FALSE 
  lMinSchema      = FALSE. 
lRetOK = DATASET DSET:WRITE-XML(cTargetType, cFile, lFormatted, cEncoding, 
  cSchemaLocation, lWriteSchema, lMinSchema). 

The following code example defines a static temp-table object, populates the temp-table object (code not shown), and writes the temp-table object to an XML document:

DEFINE VARIABLE cTargetType     AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cFile           AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lFormatted      AS LOGICAL   NO-UNDO. 
DEFINE VARIABLE cEncoding       AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cSchemaLocation AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lWriteSchema    AS LOGICAL   NO-UNDO. 
DEFINE VARIABLE lMinSchema      AS LOGICAL   NO-UNDO. 
DEFINE VARIABLE lRetOK          AS LOGICAL   NO-UNDO. 
DEFINE TEMP-TABLE ttCust NO-UNDO LIKE Customer. 
/* Code to populate the temp-table  */ 
ASSIGN 
  cTargetType     = "file" 
  cFile           = "ttCust.xml"  
  lFormatted      = TRUE 
  cEncoding       = ? 
  cSchemaLocation = ? 
  lWriteSchema    = FALSE 
  lMinSchema      = FALSE. 
lRetOK = TEMP-TABLE ttCust:WRITE-XML(cTargetType, cFile,lFormatted, 
cEncoding, 
  cSchemaLocation, lWriteSchema, lMinSchema). 

See also: ENCODING attribute, FIX-CODEPAGE statement, FOREIGN-KEY-HIDDEN attribute, NAMESPACE-PREFIX attribute, NAMESPACE-URI attribute, NESTED attribute, READ-XML( ) method, READ-XMLSCHEMA( ) method, SERIALIZE-HIDDEN attribute, SERIALIZE-NAME attribute, WRITE-XMLSCHEMA( ) method, XML-NODE-NAME attribute, XML-NODE-TYPE attribute


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex