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 after nested child tables
 
XML schema with parent table fields after nested 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 after the nested child temp-tables:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<element name="ClientInfo">
  <complexType>
     <sequence>
      <element name="Individual" minOccurs="0">
       <complexType>
        <sequence>
           <element name="LastName" type="xsd:string"/>
           <element name="FirstName" type="xsd:string"/>
           <element name="BirthDate" type="xsd:date"/>
           <element name="Gender" type="xsd:string"/>
        </sequence>
      </complexType>
</element>
<element name="Organization" minOccurs="0">
   <complexType>
     <sequence>
         <element name="OrgName" type="xsd:string"/>
         <element name="FedBN" type="xsd:string"/>
         <element name="ProvBN" type="xsd: string "/>
      </sequence>
      </complexType>
     </element>
     <element name="Language" type="xsd:string"/>
     <element name="Email" type="xsd:string"/>
    </sequence>
   </complexType>
 </element>
</schema>
In the above schema:
*The root element, ClientInfo, maps to a temp-table with a two fields, Language and Email. These fields are in the sequence after the nested child definitions.
*ClientInfo has two nested child temp-table definitions
*Individual, with four fields: LastName, FirstName, BirthDate, and Gender.
*Organization, with three fields: OrgName, FedBN and ProvBN.
The following is the static ProDataSet definition for the XML schema:
DEFINE TEMP-TABLE ClientInfo NO-UNDO
   FIELD Language AS CHARACTER
   FIELD Email AS CHARACTER.

DEFINE TEMP-TABLE Individual NO-UNDO
   FIELD LastName AS CHARACTER
   FIELD FirstName AS CHARACTER
   FIELD BirthDate AS CHARACTER
   FIELD Gender AS CHARACTER
   FIELD ClientInfo_id AS RECID XML-NODE-TYPE "HIDDEN".

DEFINE TEMP-TABLE Organization NO-UNDO
   FIELD OrgName AS CHARACTER
   FIELD FedBN AS CHARACTER
   FIELD ProvBN AS CHARACTER
   FIELD ClientInfo_id AS RECID XML-NODE-TYPE "HIDDEN".

DEFINE DATASET ClientInfoDset XML-NODE-TYPE "HIDDEN"
   FOR ClientInfo, Individual, Organization
   PARENT-ID-RELATION Relation1 FOR ClientInfo, Individual
         PARENT-ID-FIELD ClientInfo_id
PARENT-ID-RELATION Relation2 FOR ClientInfo, Organization
         PARENT-ID-FIELD ClientInfo_id
         PARENT-FIELDS-AFTER (Language, Email).
The READ-XML() and READ-XMLSCHEMA() methods create the dynamic equivalent of this static definition.