XForms is the next generation of HTML forms. In this article, we would shortly discuss about the usage of XForms in the web applications. Prior understanding of HTML, HTML forms and XHTML is required.
XForms is richer and more flexible than HTML forms and it is platform and device independent. This concept separates data and logic from presentation and also stores and transports data in XML documents. It also contains additional features like calculations and validations of forms. Separating data from presentation makes XForms device independent, because the data model can be used for all devices. The presentation can be customized for different user interfaces, like mobile phones, handheld devices, and Braille readers for the blind.
The purpose of an HTML form is to collect data. XForms has the same purpose. With XForms, input data is described in two different parts:
The XForm model – defines what the form is, what it should do, what data it contains.
The XForm user interface – defines the input fields and how they should be displayed.
Consider an example of XForms model:
1 2 3 4 5 6 7 8 9 |
<model> <instance> <person> <fname/> <lname/> </person> </instance> <submission id="form1" action="submit.asp" method="get"/> </model> |
In the example above, the XForms model uses an instance element to define the XML-template for the data to be collected, and a submission element to describe how to submit the data.
An important element in the XForms is the instance element. The instance element defines the data to be collected. XForms is always collecting data for an XML document. The instance element in the XForms model defines the XML document.
In the example above the “data instance” (the XML document) the form is collecting data for looks like this:
1 2 3 4 |
<person> <fname/> <lname/> </person> |
After collecting the data, the XML document might look like this:
1 2 3 4 |
<person> <fname>John</fname> <lname>Smith</lname> </person> |
Although forms can also be formed with the help of HTML, but XForms provide a much more powerful and rich capabilities and options for web developers. In the future articles, we would discuss some more powerful features of XForms.