When using XForms, you can reduce the form’s load and run time by nesting related binds that refer to the same nodeset. That is, you can use nested binds to group related binds together and limit the number of times the parser needs to traverse the data model, thus reducing load and run time.
When the form is opened, the parser traverses the entire form and loads each element in the data model. When it parses the binds, it must then re-traverse the data model for each bind, looking for the specified reference. When each bind is a separate entity, the parser starts at the top of the data model and works its way down until it finds the reference it is looking for. However, if related binds are nested, the parser doesn’t need to re-traverse the full data model, as it has already found the parent node of the reference it needs to look for.
For example, consider this simplified data instance:
If you have individual binds on nodesetB, child_B1, child_B2, child_B3, and child_B4, the parser would have to traverse the file 5 times to implement the binds. That’s not long in a tiny example like the one above, but parsing time increases rapidly when you have larger or more complex data models in your form. On the other hand, if you nested the binds to the child nodes inside the bind to the parent node, the parser would travel to the parent, create that bind, then move immediately through each child bind until all of the binds inside the parent bind are complete. The simplified bind structure for this example would be:
<bind with reference to parent bind>
<bind with reference to child_B1/>
<bind with reference to child_B2/>
<bind with reference to child_B3/>
<bind with reference to child_B4/>
</bind with reference to parent bind>
The following code sample shows a portion of a data instance from a tax form, which collects name, address information, and contact information. The code sample below the data instance shows a series of nested binds that reference nodes and nodesets in this data instance.
Figure 1. Data instance
<xforms:instance id="INSTANCE" xmlns="">
In the following example, the parent bind refers to the instance('INSTANCE')/composition/forms/TAX nodeset. This is the parent nodeset of the PART_2/RESIDENT_PROPERTY_OWNER_TABLE/OWNER_INFO nodeset. By nesting the OWNER_INFO bind inside the instance('INSTANCE')/composition/forms/TAX nodeset, you make it easier for parser to find the relevant nodes; instead of traversing the entire data model looking for the OWNER_INFO nodeset, the parser can start at the instance('INSTANCE')/composition/forms/TAX level, which it already found for the previous bind.
Likewise, by nesting the FIRST_NAME and LAST_NAME binds inside the OWNER_INFO bind, the parser can search for these name nodes starting at the OWNER_INFO nodeset, instead of traversing the entire form.
Figure 2. Binds that refer to elem>ents of the data instance
<xforms:bind id="SSN_VALID" nodeset="instance('INSTANCE')/composition/
<xforms:bind constraint="../SSN_VALID = 'Y'" id="PART2_SSN_VALID"
<xforms:bind id="Owner_First_Name_Required" nodeset="FIRST_NAME"
<xforms:bind id="Owner_Last_Name_Required" nodeset="LAST_NAME"
Exceptions to this practice
There are no exceptions to this practice.
Back to: Performance best practices