XForms Code for the Example Form
OpenOffice saved the data in the XForm as external XML when you saved the document. The form elements will use Binding 1 to track what form will be output where. The example shown below contains a Windows-specific file URI for the submission action; a corresponding Linux installation used file:///home/user/xforms/example3.xml
<xforms:model id="Model 1">
<xforms:instance id="Instance 1">
<xforms:bind id="Binding 1"
Table 1 shows the XForms submission options:
Table 1. XForms Submission Options: The table shows the various submission options available.
The example in this article uses the File URI Scheme to define paths simply to avoid having to configure an HTTP server to receive XML for a tutorial. However, in my experience, the File URI scheme is inadequate for production work with OpenOffice, because it requires absolute paths and does not have graceful error handling when files are locked for editing.
A form element that uses the XForm binding shown earlier would look like Listing 1
. The important parts of Listing 1
are the form:id
attribute on the form:text
element, which is the identifier that the text fields use to figure out the type of form input they hold, and the xforms:bind
attribute, which declares that this form element binds to an XML element in the XForms instance using the xforms:bind
element that has an id of StreetName
Finally, the code draws the input field, using presentational markup that defines the display of the form field. Actual form elements are represented using the "draw" namespace.
The control is bound to the form input via the id
reference used in the draw:control
attribute. OpenOffice draws controls with absolute placement via the x, y coordinates—you cannot rely on OpenOffice to place a field automatically in document flow; the explicit coordinates are required.
|Figure 8. Understanding Connections: The graph shows the relationships between controls, form items, and the XForms model.|
You can understand the relationships between the various form elements most easily by moving from the rendered elements back to their connections via the Form Controls to the XForms element (see Figure 8
Moving from left to right in Figure 8
, the drawn control is bound to the abstract control in the form via the draw:control
attribute. For example, the first control has a draw:control
attribute value of control1
. Note that control1
is the form:id
of the button on the form.
Using the relationship information, you can now make an OpenOffice XForm without designing it as an end user. Instead, you can just write the markup directly.