Try OpenEdge Now
skip to main content
Working with XML
Reading and Writing XML Data from Temp-Tables and ProDataSets : Writing XML Schema from a temp-table, temp-table buffer, or ProDataSet : Writing a temp-table definition to XML Schema
 

Writing a temp-table definition to XML Schema

The following code example creates a dynamic temp-table and writes its definition to an XML Schema file:
/* pi-tfx-write-1.p */
/* Writes an XSD file from a dynamic temp table. */

{pi-tfx-parameterVarDefs.i}

DEFINE VARIABLE httCust AS HANDLE  NO-UNDO.
DEFINE VARIABLE lReturn AS LOGICAL NO-UNDO.

CREATE TEMP-TABLE httCust.
httCust:CREATE-LIKE("Customer").
httCust:TEMP-TABLE-PREPARE("ttCustomer").

ASSIGN
  cTargetType = "FILE"
  cFile       = "ttCust2.xsd"
  lFormatted  = YES
  cEncoding   = ?
  lMinSchema  = NO.

lReturn = httCust:WRITE-XMLSCHEMA(cTargetType, cFile, lFormatted,
  cEncoding, lMinSchema).
Note that the min-xmlschema method option (lMinSchema = NO) is set to NO, which means that the AVM will use all the XML Schema extension attributes necessary to fully restore objects in the ABL environment. Here is an example portion of the .xsd file generated by this code:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:prodata="urn:schemas-progress-com:xml-prodata:0001">
<xsd:element name="ttCustomer" prodata:proTempTable="true">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ttCustRow" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CustNum" type="xsd:int" nillable="true"
                 prodata:format=">>>>9" prodata:label="Cust Num"
                 prodata:help="Please enter a customer number."/>
<xsd:element name="Country" type="xsd:string" nillable="true"
                 default="USA" prodata:format="x(20)" prodata:help="Please
                   enter a country."/>
<xsd:element name="Name" type="xsd:string" nillable="true"
                 prodata:format="x(30)" prodata:help="Please enter a
                   name."/>
. . .
Re-run this code with the min-xmlschema method option set to YES (lMinSchema = YES), which means that the AVM will use only use a small subset of its XML Schema extension attributes. The XML Schema will still identify temp-tables, ProDataSets, and data relations, and, if necessary, it will provide datatype and initial attributes. For example, here is a portion of the .xsd file generated by this code with min-xmlschema set to YES:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:prodata="urn:schemas-progress-com:xml-prodata:0001">
<xsd:element name="ttCustomer" prodata:proTempTable="true">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ttCustRow" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CustNum" type="xsd:int" nillable="true"/>
<xsd:element name="Country" type="xsd:string" nillable="true"
                   default="USA"/>
<xsd:element name="Name" type="xsd:string" nillable="true"/>
. . .