XML Data Element Example

An application can group XML data elements to be formatted together as an entity by grouping those elements hierarchically under a collection XML data element. The data order normally does not matter in formatting the data elements unless the elements are to be placed relative to each other in the inline direction. Any elements to be placed inline relative to each other must be ordered in inline presentation order. Use the XLAYOUT/FIELD commands to place the data on the presentation device. Figure XML Data Elements is an example of a bank customer showing the name and address fields placed together:

XML Data Elements

<Customer>
  <name>
    <title>Dr.</title>
    <first>Kelly</first>
    <last>Green</last>
  </name>
  <address>
    <strno>1911</strno>
    <street>Colt Lane</street>
    <city>Longmont</city>
    <state>CO</state>
    <zip>80501</zip>
  </address>
</Customer>

The example in Figure XML Data Elements results in the following printed output:

Dr. Kelly Green
1911 Colt Lane
Longmont, CO 80501

The page definition used to create the output is as follows:

PAGEDEF xmp101 UDTYPE ebcdic REPLACE yes;
/*------------------------------------------------------*/
/* Font definitions:
/*------------------------------------------------------*/
FONT E21H0C TYPE EBCDIC;

/*------------------------------------------------------*/
/* Use QTAG definitions to define short alias names     */
/* that make coding the XLAYOUTs easier. Do the         */
/* messy work here, allowing us to code on the XLAYOUT: */
/*  XLAYOUT zip …                                     */
/* instead of:                                          */
/*  XLAYOUT QTAG 'Customer','address','zip' …         */
/*------------------------------------------------------*/
Define cust   QTAG 'Customer'                ;
Define title  QTAG 'Customer','name' ,'title';
Define first  QTAG 'Customer','name' ,'first';
Define last   QTAG 'Customer','name' ,'last' ;
Define strno  QTAG 'Customer','address' ,'strno' ;
Define street QTAG 'Customer','address' ,'street' ;
Define city QTAG 'Customer','address','city' ;
Define state  QTAG 'Customer','address' ,'state' ;
Define zip    QTAG 'Customer','address' ,'zip' ;

/*------------------------------------------------------*/
/* Print first line "Dr. Kelly Green"                   */
/* NOTE:-The "collector" Customer starts a new page     */
/*  -RELATIVE 0 is not the same as SAME                 */
/*  -RELATIVE 0.167 is equivalent to a 6 CPI space      */
/*  along with FIELD TEXT, giving us 2 ways to          */
/*  leave a space.                                      */
/*  -Watch out for the POSITION defaults on XLAYOUT     */
/*  and FIELDs                                          */

/*------------------------------------------------------*/
XLAYOUT cust           NEWPAGE;
XLAYOUT title  POSITION ABSOLUTE 1 in ABSOLUTE 1 in;
XLAYOUT first  POSITION RELATIVE 0 in RELATIVE 0;
 FIELD TEXT'';
 FIELD START 1 LENGTH *;
XLAYOUT last   POSITION RELATIVE 0.167 in RELATIVE 0;
/*------------------------------------------------------*/
/* Print second line "1911 Colt Lane"                */
/*------------------------------------------------------*/
XLAYOUT strno POSITION ABSOLUTE 1 in NEXT;
XLAYOUT street POSITION RELATIVE 0 RELATIVE 0;
 FIELD TEXT'';
 FIELD START 1 LENGTH *;

/*------------------------------------------------------*/
/* Print third line "Longmont, CO 80501"                */
/*------------------------------------------------------*/
XLAYOUT city  POSITION ABSOLUTE 1 in NEXT;
XLAYOUT state POSITION RELATIVE 0 RELATIVE 0;
 FIELD TEXT',';
 FIELD START 1 LENGTH 2;  /*just the abbreviation/*
XLAYOUT zip   POSITION RELATIVE 0 RELATIVE 0;
 FIELD TEXT'';
 FIELD START 1 LENGTH *;

In the above example, the XML data items Dr., Kelly, and Green are printed relative to each other using relative inline positioning. This can only be done because the data appears in the following order: the title, Dr. is first; the first name, Kelly is next;, and the last name, Green is last. However, if you wanted to use this data, and change the order of the names to print the last name followed by the first name, you must position the names using absolute inline positioning, because the data cannot be reordered using relative inline positioning.