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 : Simple example of a PARENT-ID-RELATION
 
Simple example of a PARENT-ID-RELATION
The following is a sample XML file with nested child tables.
<?xml version="1.0" encoding="UTF-8"?>
<CustomerOrders>
 <Customer>
  <CustNum>1</CustNum>
  <Name>LiftTours</Name>
  <Order>
    <OrderNum>100</OrderNum>
    <OrderTotal>1234.89</OrderTotal>
</Order>
<Order>
   <OrderNum>150</OrderNum>
   <OrderTotal>999.99</OrderTotal>
  </Order>
</Customer>
<Customer>
  <CustNum>3</CustNum>
  <Name>Hoops</Name>
  <Order>
     <OrderNum>200</OrderNum>
     <OrderTotal>1899.99</OrderTotal>
   </Order>
  </Customer>
</CustomerOrders>
In the above XML file, CustomerOrders is a DataSet with two member tables:
*Customer with two fields, CustNum and Name
*Order with two fields, OrderNum and OrderTotal
Although there is no matching field between the nested Customer and Order tables, the PARENT-ID-RELATION phrase provides syntax for specifying a relationship between Customer and Order records based on the RECID of the parent Customer record.
The following is a static ProDataSet definition for the above XML document:
DEFINE TEMP-TABLE Customer NO-UNDO
    FIELD CustNum as INTEGER
    FIELD Name as CHARACTER.

DEFINE TEMP-TABLE Order NO-UNDO
    FIELD OrderNum AS INTEGER
    FIELD OrderTotal AS DECIMAL
    FIELD Customer_id AS RECID XML-NODE-TYPE "HIDDEN".

DEFINE DATASET CustomerOrders FOR Customer, Order
    PARENT-ID-RELATION Relation1 FOR Customer,
    Order PARENT-ID-FIELD Customer_id.
The ABL code to create the data for the CustomerOrders ProDataSet and write out the XML is as follows:
CREATE Customer.
ASSIGN CustNum = 1
    Name = "Lift Tours".

CREATE Order.
ASSIGN OrderNum = 100
    OrderTotal = 1234.89
    Customer_id = RECID(Customer).

CREATE Order.
ASSIGN OrderNum = 150
    OrderTotal = 999.99
    Customer_id = RECID(Customer).

CREATE Customer.
ASSIGN CustNum = 3
    Name = "Hoops".

CREATE Order.
ASSIGN OrderNum = 200
    OrderTotal = 1899.99
    Customer_id = RECID(Customer).

DATASET CustomerOrders:WRITE-XML("file", "CustomerOrders.xml", TRUE).