Try OpenEdge Now
skip to main content
Working with XML
Reading and Writing XML Data from Temp-Tables and ProDataSets : Using XML Schema : Examples of additional XML support : XML schema with parent table fields interspersed among child tables
 
XML schema with parent table fields interspersed among child tables
The following example demonstrates the functionality provided to create a DATASET definition from an XML schema where the parent fields of a temp-table are defined both before and after the nested child temp-tables:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<element name="Buy">
   <complexType>
    <sequence>
      <element name="TrxnTyp" type="xsd:string"/>
      <element name="Amt">
        <complexType>
          <sequence>
            <element name="AmtType" type="xsd:string"/>
            <element name="AmtValue" type="xsd:string"/>
          </sequence>
       </complexType>
      </element>
     <element name="TaxCode" type="xsd:string"/>
     <element name="ClientComm" type="xsd:string"/>
     <element name="Payment" minOccurs="0">
  <complexType>
       <sequence>
         <element name="PayType" type="xsd:string"/>
         <element name="Currency" type="xsd:string"/>
       </sequence>
      </complexType>
     </element>
    <element name="Comments" type="xsd:string"/>
   </sequence>
  </complexType>
 </element>
</schema>
In the above schema:
*The root element, Buy, maps to a temp-table with four fields: TrxnTyp, TaxCode, ClientComm, and Comments
*Buy has two nested child temp-table definitions:
*Amt, with two fields: AmtType and AmtValue
*Payment, with two fields: PayType and Currency
*The TrxnTyp field from the Buy temp-table is defined before the nested Amt temp-table definition.
*The TaxCode and ClientComm fields from the Buy temp-table are defined after the nested Amt temp-table.
*The Comments field from the Buy temp-table is defined after the nested Payment temp-table definition.
The following is the static ProDataSet definition for the XML schema:
DEFINE TEMP-TABLE Buy NO-UNDO
     FIELD TrxnTyp AS CHARACTER
     FIELD TaxCode AS CHARACTER
     FIELD ClientComm AS CHARACTER
     FIELD Comments AS CHARACTER.

DEFINE TEMP-TABLE Amt NO-UNDO
     FIELD AmtType AS CHARACTER
     FIELD AmtValue AS CHARACTER
     FIELD Buy_id AS RECID XML-NODE-TYPE "HIDDEN".

DEFINE TEMP-TABLE Payment NO-UNDO
     FIELD PayType AS CHARACTER
     FIELD Currency AS CHARACTER
     FIELD Buy_id AS RECID XML-NODE-TYPE "HIDDEN".

DEFINE DATASET BuyDset XML-NODE-TYPE "HIDDEN"
     FOR Buy, Amt, Payment
     PARENT-ID-RELATION Relation1 FOR Buy, Amt
              PARENT-ID-FIELD Buy_id
                PARENT-FIELDS-BEFORE (TrxnTyp)
                PARENT-FIELDS-AFTER (TaxCode, ClientComm)
     PARENT-ID-RELATION Relation2 FOR Buy, Payment
              PARENT-ID-FIELD Buy_id
                PARENT-FIELDS-AFTER (Comments).
READ-XML() or READ-XMLSCHEMA() creates the dynamic equivalent of this static definition.
Since the Relation1 PARENT-ID-RELATION contains a PARENT-FIELDS-BEFORE and PARENT-FIELDS-AFTER phrase, the TrxnTyp fields of a Buy temp-table record is written to XML before any Amt child records, and TaxCode and ClientComm fields are written to XML after all Amt child records.
Since the Relation2 PARENT-ID-RELATION contains a PARENT-FIELDS-AFTER phrase, the Comments field of a Buy temp-table record is written to XML after all Payment child records.