Example
This example uses a DataWindow object that includes the
columns emp_id, emp_fname, emp_lname, and dept_id. The template used
in this example includes only these columns. Any other columns in
the DataWindow remain empty when you import using this
template.
To illustrate how template import works, create a new template
that has one element in the header section, called
before_detail_marker. This element contains a column reference to
the emp_id column.
The Detail Start element, employee, has an attribute, dept_id,
whose value is a control reference to the column dept_id. It also
has three children:
-
The emp_id element contains a column reference to the
emp_id column. -
The emp_fname element contains static text.
-
The name element has two children, emp_fname and
emp_lname, that contain column references to those
columns.
The template exports and imports the dept_id DataWindow column
using the attribute of the employee element. It exports and imports
the emp_id, emp_fname, and emp_lname columns using the column
references in the elements. The following shows the beginning of the
XML exported using this template:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0" encoding="UTF-16LE" standalone="no"?> <employee_list> <before_detail_marker>102</before_detail_marker> <employee dept_id="100"> <emp_id>102</emp_id> <emp_fname>static text content</emp_fname> <name> <emp_fname>Fran</emp_fname> <emp_lname>Whitney</emp_lname> </name> </employee> <employee dept_id="100"> <emp_id>105</emp_id> <emp_fname>static text content</emp_fname> <name> <emp_fname>Matthew</emp_fname> <emp_lname>Cobb</emp_lname> </name> </employee> ... |
The exported XML can be reimported into the DataWindow columns
dept_id, emp_id, emp_fname, and emp_lname. Before importing, you
must set the import template on the Data Import page in the
Properties view or in a script using the DataWindow object’s
Import.XML.UseTemplate property.
The following items are exported, but ignored on
import:
-
The before_detail_marker element is ignored because it is
in the header section. -
The first occurrence of the element tag name emp_fname is
ignored because it does not contain a mapping to a DataWindow
column name.
If you change the nesting of the emp_fname and emp_lname
elements inside the name element, the import fails because the order
of the elements and the nesting in the XML and the template must
match.