Back to Contents


The TypeInfo class

Summary:

See also: Classes and Objects


Syntax

The TypeInfo class is a built-in class provided to serialize program variables.

Syntax:

base.TypeInfo

Notes:

  1. This class does not have to be instantiated.

Methods

Class Methods
Name Description
create( variable )
  RETURNING om.DomNode
Creates a DOM node from a program variable

Usage

Use the TypeInfo class to serialize program variables in an XML format. For example, you can fetch rows from a database table in an array, specify the array as the input into the base.TypeInfo.create() method, write the resulting DomNode to a file using the node.writeXml() method, and give the resulting file to any application that is able to read XML for input.

Creating a TypeInfo object

The create() method of this class builds a DomNode object from any kind of structured program variable, thus serializing the variable:

01 MAIN
02   DEFINE n om.DomNode
03   DEFINE r RECORD
04       key INTEGER,
05       lastname CHAR(20),
06       birthdate DATE
07   END RECORD
08   LET r.key = 234
09   LET r.lastname = "Johnson"
10   LET r.birthdate = MDY(12,24,1962)
11   LET n = base.TypeInfo.create( r )
12   CALL n.writeXml( "r.xml" )
13 END MAIN

The generated node contains variable values and data type information. The above example creates the following file:

<?xml version="1.0"? encoding="ISO-8859-1">
<Record>
  <Field type="INTEGER" value="234" name="key"/>
  <Field type="CHAR(20)" value="Johnson" name="lastname"/>
  <Field type="DATE" value="12/24/1962" name="birthdate"/>
</Record>

Note that data is formatted according to current environment settings (DBDATE, DBFORMAT, DBMONEY).