Chapter 4, Exchanging Data Between an External Application
and a Basic XFA Form
XFA Specification
Basic Data Binding to Produce the XFA Form DOM
157
Principles of Data Binding
Data binding supports data independence, which is a key XFA feature.
Data independence
allows a form
designer to change a template without requiring that corresponding changes be made to the structure of
the data. It also allows the same data to be used with different templates. Data independence is enhanced
by retaining the original structure of the XML Data DOM and the values of any objects in the XML Data
DOM that are not used by the template.
Data binding is sometimes called
merging
or the
merge process.
This refers to the goal of data binding,
which is to merge the data with the template. Data binding achieves this by creating the Form DOM, which
instantiates the mapping between the data and the template. The Form DOM is actively linked to the XFA
Data DOM so that changes made to data values in the Form DOM propagate automatically into the Data
DOM and vice-versa. The Form DOM can be thought of as the filled-in form. Indeed, scripts usually act
upon the Form DOM rather than dealing directly with either the Template DOM or the XFA Data DOM.
Extraneous data may be present in the Data DOM; it is preserved but does not take part in the mapping.
Likewise subforms may optionally be included in the Form DOM even though unmatched by data; the
fields within such subforms receive default values. The Form DOM may also be organized differently from
the incoming data, with content reordered and/or redistributed into subforms. Hence, some changes can
be made to the organization and content of the template independently of the format of the incoming
data. Some changes can also be made to the data independently of the template. The binding algorithm
handles such changes without any need for scripting.
The exact behavior of the data-binding process is defined in later sub-sections of this specification. Here is
a simplified overview:
The data binding process walks through the Template DOM and Data DOM, populating the Form DOM
with nodes. If a Data DOM was supplied, the data binding process attempts to match up each new form
node with a data node in accordance with the following rules:
●
●
●
●
Explicit bind targets defined in the template take precedence over automatic bindings.
For automatic bindings the relative order of same-named data values or groups
is
significant.
For automatic bindings the relative order of uniquely-named data values or groups
is not
significant.
For automatic bindings the hierarchy of structure described by data values or groups
is
significant.
The rules for automatic bindings are equivalent to the ones used for resolving SOM expressions. Indeed
one way of describing the matching process is that the data binding process attempts to find a data node
such that, when the path from the root of the Data DOM to the data node is written as an unqualified SOM
expression, the resulting SOM expression matches the form node as seen from the root of the Form DOM.
This is explained in more detail later.
The data binding process sometimes adds data nodes but it never deletes any data nodes. In addition it
reads but does not modify the Template DOM. On the other hand it populates the Form DOM.
The Bind Element
Each subform, field, and exclusion group object in the Template DOM and Form DOM has a
bind
property,
corresponding to the
bind
element in an XML template. The
bind
property contains various
sub-properties controlling the object's behavior during data binding and afterward. The sub-properties
are
match
,
picture
, and
ref
.