As you read in the previos chapter, XForms accomplishes the data capture through two
components, XForms Model and XForms User Interface. The connection between these two
parts is called binding, and it uses the common W3C technology called as XPath.
A D V E R T I S E M E N T
In order to take the advantages of binding, form authors need to provide the XML template,
called as instance data, which provides the place to reside for entered data. The
instance of data can either be empty initially (for the blank form) or can hold an initial
data (in case of the pre-populated form). The ref attribute on each of the form control,
seen previously, actually holds the XPath expression that points to the location in an
instance the data.
If you've had some sort of experience with XPath, you probably know that the XPath deals
with a node-sets, where a node is the fundamental bit of the XML such as an element or
an attribute. Whenever the XForms uses ref attribute, it aplies the first node rule, so
that even if the XPath would normally return several nodes, only the first (in the order
that things appears in a document) is used by the XForms. In contrast, the attribute
node set indicates that the multiple nodes are in play.
A note on namespaces
Any of the serious XML work will inevitably run into an XML namespaces, with a telltale
xmlns attributes. Since this is the XForms Institute, and not a Namespaces Institute,
several of the simplifications are used here:
The default namespace
A default namespace is applied to an XHTML. It is possible that by the time XHTML 2 is
finialized that an XForms will share a namespace, so the XForms elements too are considered
as default. .
The user namespace
A prefix my: is used for most of the user-provided instance data.
The few other namespace prefixes, such as ev: for an XML Events may appear, and it will
be explained as needed.
Keep in mind that in the XPath expressions, no default namespace is applied, and thus the
prefixes should be used liberally.
How the binding works
First of all, as the child of a model element, an element called as instance is needed
to provide an instance of the data, which can be either an inline XML, or in the
separate document pointed to by the src attribute. Cosider for an example, a fragment of
the UBL document:
This sample of code includes a submission element as before, and additionally an
instance of the element populated with a real-world XML. It also has the bind element,
the key to the power of an XForms: it can do work directly with nearly any kind of the
XML in existence.
A nodeset attribute gives the hint of how this element will work: it selects all of the
my:Description elements in a document. In the purchase order, you would expect several
of the line items to be present, each with the description field. An XPath expression
do selects them all, and applies the property called "required" to each of them.
An XPath works much like the directory path, with each step descending one level into
an XML. An attribute step is accomplished with the leading character @, as in an