Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Getting Started with XForms in OpenOffice : Page 3

Discover how to design and customize XForms in OpenOffice.




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

Adding Controls
Next, you'll add a submission button to the form. Choose the Button control from the form controls panel, move to the designer, and draw a rectangle for the button, sizing it as you prefer. By default, the button will "snap" to the upper left corner of the document. If you don't like the button placement, you can right click on it, choose Position and Size from the context menu, and change the anchor from "As Character" to one of the other available values.

Figure 6. Edit Submissions Form: On this form, enter an action, select a method, and give the submission a name.
The various 'Position and Size" stylings are outside the purview of this article, but the "As Character" setting makes the form control part of the normal document flow; if you don't really have other content in the document anchoring the form as character sets the field to be displayed at the document's outer left margin.

Click the Submissions tab of the XForms Model panel on the right. The first icon in the panel is "Add Submission;" select that icon. The "Edit Submission" form that pops up looks like Figure 6.

Add a name of your choice, set the file action to be file:/// and enter a location where you want the file output to be saved in the file system. For example, in Windows you might choose file:///c:/xforms/Example2.xml. Next, set the method to be Put, and select "Document" for the Replace field so the submission will overwrite any existing document.

Now you have a place to submit a file and a button—you just need to bind the two. Right click on the button and select "Control" from the context menu.

Figure 7. Text Box Properties: These settings bind the XPath expression
to the form model.
Add a text box so users can edit the element. Choose the text box icon from the forms control, and then click on the page and resize the control as desired.

Right-click on your text box and choose "Control." Edit the properties so they match in the contents of Figure 7.

The Binding expression field is an XPath expression. When using XPath in XForms it is by default rooted on the document element of the to-be-generated output instance, which in this case is the default instanceData element used by OpenOffice. Therefore, the Binding expression field value in Figure 7 actually means the XPath selected will be /instanceData/AddressPortal. This convention is a bit of syntactical sugar, the benefit of which I've never understood.

If everything works so far, you should be able to turn off Design Mode, write Hello World in the text field and push your submit button. Assuming the folder exists that your file path references, you should see a new file appear containing the following XML:

<?xml version="1.0"?> <instanceData> <AddressPostal> Hello World </AddressPostal> </instanceData>

While the preceding file format does not yet match the final target XML, it does provide an example of how editing the XForm can create an XML document.

XForms Syntax in OpenOffice
As you may have noticed from the UI, XForms in OpenOffice are analogous to the common MVC architecture: the Model is the XForm Model, the View is the rendered form fields, and the control is OpenOffice Forms. Note that the OpenOffice Forms Namespace abstractly describes a form and its properties—the actual forms input portion of the XForms specification is not implemented. This varies from the XHTML model of XForms, because there's no clear analog to the Controller in that model.

You can look at the code that comprises the example form you designed earlier by extracting the document named Content.xml from your OpenOffice document using an unzip tool.

The document you'll see is ordered into several sections: a styling section holding all document styles, the XForm section which contains our data, any XML Schemas, and submission information, a Form Controls section which holds the bindings between the actual Form fields and the XML, and the section holding the drawn controls themselves.

The following examples show the relevant XForm and bindings.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date