Application Development


Chapter 22 . Using XML Data

As of Panther 5, you can import and export data from a Panther screen in XML format.


Defining XML Properties

To use the XML feature available as of Panther 5, the screen and its widgets must have the appropriate XML properties set. There are four XML properties that can be specified for widgets or screens:

XML Tag
A tag associated with the screen, container, or widget.

XML Attributes
Additional information to be output in the opening tag following the XML Tag value.

For example, if the XML Tag is gadget and the XML Attributes is magnetic color='blue', the opening tag in the generated XML would be:

<gadget magnetic color='blue'>

Note: If you use special characters, such as > or <, they must be escaped.

XML Prefix
Data to be output before the opening tag. This property can contain more than one line of text and will be output even if the widget does not have the XML Tag property set.

XML Postfix

Data to be output after the closing tag. This property can contain more than one line of text and will be output even if the widget does not have the XML Tag property set.

Defining XML Screen Properties

The screen being used for XML generation must either have the XML Tag property specified or both the XML Prefix and the XML Postfix properties specified.

For screens, if the XML Prefix property is empty, the generated XML starts with the following line:

<?xml version='1.0'?>

If a different opening line is needed, specify it in the screen's XML Prefix property.


Processing XML Properties

For screens and other containers (boxes, tab decks, tab cards and grids), Panther generates the following:

For data entry and selection widgets (dynamic labels, single line text widgets, multiline text widgets, option menus, combo boxes and list boxes), Panther generates the following :

Processing XML for Multiple Occurrences

When a grid is converted to XML, the maximum number of occurrences of each grid member having an XML Tag property determines the number of occurrences to output. All offscreen data will be written to the XML.

Processing Hidden Widgets

It is recommended that all widgets used in the XML generation have the same value for Hidden Always. Either all of the widgets must be set to Hidden Always, or none of the widgets must be set to Hidden Always.


Generating XML

You can generate XML by calling one of the following functions:

The form of the function depends on how you specify the screen or LDB.

The following JPL procedure generates XML for the current screen to the file titles.xml:

proc export
call sm_xml_export_file("titles.xml")
return

Importing XML

You can import XML by calling one of the following functions:

The form of the function depends on how you specify the screen or LDB.

The following JPL procedure reads in XML for the current screen from the file titles.xml:

proc import
call sm_xml_import_file("titles.xml")
return

Notes:


Sample XML File

S

The following file contains the data from one of the videobiz database screens:

<?xml version='1.0'?>
<titles>
<title_id>2</title_id>
<name>Aliens</name>
<genre>SCFI</genre>
<rating>R</rating>
<release_year>1986</release_year>
<title_id>4</title_id>
<name>All the President&apos;s Men</name>
<genre>DRAM</genre>
<rating>PG</rating>
<release_year>1976</release_year>
<title_id>26</title_id>
<name>Moonstruck</name>
<genre>COM</genre>
<rating>PG</rating>
<release_year>1987</release_year>
</titles>