The purpose of this document is to provide a detailed breakdown of XForms, specifically the subset of XForms implemented by JavaRosa, so that anyone can make their own. As of this writing there are several tools to help create your own XForms that work on JavaRosa platforms. They all allow you to create XForms, though generally the easier they are to use the less advanced functionality they provide. This set of pages will hopefully allow you to manually edit forms to your specific needs.
Overview
XForms consist of three major components:
- The instance -- where your data is going to be stored. For each prompt, you need a place to store your answer.
- The bindings -- For each instance variable, you can include information about that data like the type (string, integer, etc..), the constraints on that data (i.e. less than 3), whether it’s required or not, etc....
- The body -- How prompts are displayed to the user.
<h:html xmlns="http://www.w3.org/2002/xforms"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jr="http://openrosa.org/javarosa">
<h:head>
<h:title>Simple Form</h:title>
<model>
<!-- instance -->
<instance>
<data>
<mystring/>
</data>
</instance>
<!-- bindings -->
<bind nodeset="/data/mystring" type="string"/>
</model>
</h:head>
<!-- body -->
<h:body>
<input ref="mystring">
<label>This is a string prompt</label>
<hint>You don't need a hint, but you can add one</hint>
</input>
</h:body>
</h:html>
Instance
Let's start with the instance:
<instance>
<data>
<mystring/>
</data>
</instance>
In this example we have a single instance called "data" (which could be called anything, really) and that instance has a single variable called "mystring." Note that </mystring> is where we're going to store the answer to our prompt, but it's only a placeholder. We do _NOT_ specify a data type here.
An instance also represents a saved or completed version of the form. When you are done, the output will look like this:
<instance>
<data>
<mystring>Hello World! This is my answer!</mystring>
</data>
</instance>
Similarly, if you populate <mystring> in the original xform, it fills that in as the default answer to a prompt:
<mystring>Default answer</mystring>
Adding more prompts is as simple as adding more variables:
<instance>
<data>
<mystring/>
<a_number/>
<birthday/>
<date>2010-06-15</date>
<select>a c</select>
<favorite_number>7</favorite_number>
<whatever_i_want/>
</data>
</instance>
Variable names can be anything you want. The only caveat is that they must not contain spaces
<my_variable/> is legal.
<my variable/> is not.
