XML - Managing Data Exchange/XForms

What Is XForms?
Forms are an important part of many web applications today. An HTML form makes it possible for web applications to accept input from a user. Web users now do complex transactions that are starting to exceed the limitations of standard HTML forms. XForms is the next generation of HTML forms and is richer and more flexible than HTML forms. XForms uses XML for data definition and HTML or XHTML for data display. XForms separates the data logic of a form from its presentation. 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 and handheld devices and can provide interactivity between such devices. It is also possible to add XForms elements directly into other XML applications like VoiceXML (speaking web data), WML (Wireless Markup Language), and SVG (Scalable Vector Graphics).

The Purpose of XForms
XForms is the separation of purpose from presentation. For example, the purpose of a questionnaire application is to collect information about the user. This is done by creating a presentation that allows the user to provide the required information. Web applications typically render such a presentation as an interactive document that is continuously updated during user interaction. By separating the purpose from its presentation, XForms enables the binding of different interactions to a single model.

The Main Aspects of XForms
The XForms model defines what the form is, what data it contains, and what it should do. The XForms user interface defines the input fields and how they should be displayed. The XForms Submit Protocol defines how XForms send and receive data, including the ability to suspend and resume the completion of a form. XForms is "instance data", an internal representation of the data mapped to the familiar "form controls". Instance data is based on XML and defined in terms of XPath’s internal tree representation and processing of XML

The XForms Framework
With XForms, input data is described in two different parts:
 * 1) XForm model
 * 2) XForm user interface

The XForms Model
The XForm model defines what the form is, what data it contains, and what it should do.

The data model is an instance (a template) of an XML document. The XForms model defines a data model inside a element: 

From the example above, you can see that the XForms model uses an element to define the XML template for data to be collected, and a element to describe how to submit the data.

The XForms model does not say anything about the visual part of the form (the user interface).

The Element
The data collected by XForms is expressed as XML instance data. XForms is always collecting data for an XML document. The 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: After collecting the data, the XML document might look like this: Jim Jones

The Element
The XForms model uses a element to describe how to submit the data. The element defines a form and how it should be submitted. In the example above, the id="form1" attribute identifies the form, the action="submit.asp" attribute defines the URL to where the form should be submitted, and the method="get" attribute defines the method to use when submitting the data.

The following diagram shows how the XForm model has the capability to work with a variety of user interfaces.

The XForms User Interface
The XForms user interface is used to display and input the data. The user interface elements of XForms are called controls (or input controls): First Name Last Name Submit In the example above the two elements define two input fields. The ref="fname" and ref="lname" attributes point to the and elements in the XForms model. The element has a submission="form1" attribute which refers to the element in the XForms model. A submit element is usually displayed as a button. Notice the elements in the example. With XForms every input control element has a required element.

Putting Everything Together
XForms has to run inside another XML document. It could run inside XHTML 1.0, and it will run inside XHTML 2.0. If we put it all together, the document will look like this:  First Name Last Name Submit

The XForms Processor
An XForms Processor built into the browser will be responsible for submitting the XForms data to a target. The data can be submitted as XML and could look something like this:

Jim Jones

Or it can be submitted as text, looking something like this: fname=Jim;lname=Jones

The XForms Namespace
The official namespace for XForms is: http://www.w3.org/2002/xforms. If you want to use XForms in HTML (or XHTML 1.0), you should declare all XForms elements with an XForms namespace. XForms is expected to be a standard part of XHTML 2.0, eliminating the need for the XForms namespace.

An XForms Example
Take a look at this document using XForms:  First Name

Last Name

Submit

The Form Controls
The components of the form that deal with data entry and display are referred to as the form controls or user interface controls. XForms defines a comprehensive set of device-neutral, platform-independent form controls. For each element of data defined in the model, a form control defines its appearance via the client. These controls can be combined with stylesheets to provide sophisticated form displays.

XForms Action
In the course of form processing, often some particular action needs to happen.

XForms Methods
The XForms specification uses and builds upon XPath, which includes adding some method calls useful for forms: These can be called at any point where XPath is allowed. Additionally, implementations can support “extension functions” to provide additional functionality.