Browse DevX
Sign up for e-mail newsletters from DevX


Getting Started with XForms in OpenOffice : Page 4

Discover how to design and customize XForms in OpenOffice.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

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"> <instanceData> <AddressPostal>Hello World</AddressPostal> </instanceData> </xforms:instance> <xforms:bind id="Binding 1" nodeset="AddressPostal"/> <xforms:submission id="submitthis" action="file:///c:/xforms/example3.xml" method="put" indent="false" omit-xml-declaration="false" standalone="false" replace="none"/> <xsd:schema/> </xforms:model>

Table 1 shows the XForms submission options:

Table 1. XForms Submission Options: The table shows the various submission options available.
Protocol/URI Scheme Submission options
HTTP form-data-post
HTTPS form-data-post
MailTo form-data-post
File Put

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.

<text:p text:style-name="Standard"> <draw:control text:anchor-type="paragraph" draw:z-index="0" draw:style-name="gr1" draw:text-style-name="P2" svg:width="2.943cm" svg:height="1.165cm" svg:x="12.217cm" svg:y="4.258cm" draw:control="control1"/> <draw:control text:anchor-type="paragraph" draw:z-index="1" draw:style-name="gr2" draw:text-style-name="P3" svg:width="6.584cm" svg:height="0.763cm" svg:x="4.597cm" svg:y="1.951cm" draw:control="control2"/> </text:p>

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.

Bryan Rasmussen has been employed by the Danish Government's Data Standardization Project OIOXML with an overview of Core XML and Web technologies, as well as the Danish subset of UBL. He currently works for Software Innovation, one of the Danish Government authorized distributors of FESD Software.
Thanks for your registration, follow us on our social networks to keep up-to-date