XML.com: XML From the Inside Out
oreilly.comSafari Bookshelf.Conferences.


What Are XForms
by Micah Dubinko | Pages: 1, 2

Actions sans Script

Other than a few special cases (submit and reset) the way to make today's web forms do something is through scripts attached to "intrinsic" event attributes like onFocus. With the mission of reducing the need for scripts, the HTML Working Group and XForms Working Group have jointly developed a general purpose event framework called XML Events. It provides an XML interface to DOM Level 2 STYLE events. It also enables the definition of markup-based (a.k.a. script-free) XForms Actions.

Using an element-based declarative syntax, XForms authors can:

  • set focus to a form control
  • display a message to the user
  • navigate to a new URI (in the same or a new window)
  • change the value of an instance data node
  • force a recalculation, revalidation, or screen refresh
  • submit or reset all or a portion of the instance data
  • perform other actions to deal with scrolling and manipulating repeating line item tables

In this example, a form authored for a resource-limited device might wish to recalculate only when a trigger is activated:


  <xforms:label>Click to Recalculate</xforms:label>

  <xforms:action ev:event="xforms-activate">




(Note that the xforms prefix represents the XForms namespace and the ev prefix represents the XML Events namespace.)

XForms in XHTML

While the XForms language is suitable for inclusion in any number of other XML document formats, the sweet spot is its combination with XHTML. Working Drafts of XHTML 2.0 indicate that the old forms technology will not be included in the standard, being replaced by XForms.

The following example will walk through a basic form -- collecting a credit card number in the simplest way possible.

In XHTML, a form is completely enclosed within <form>...</form> tags. In contrast, the XForms solution separates purpose, represented by the "XForms Model" (the name for the non-visible form data plus annotations), from presentation, represented by the form controls. This means that adding a single form to a containing document usually involves inserting markup in multiple places.

The XForms Model belongs in the header section or within the <head> element of XHTML:

<html xmlns="http://www.w3.org/2002/06/xhtml2"



    <title>Example of XHTML plus XForms</title>

      <xforms:model id="myform">

      <xforms:submission action="https://example.com/cc-submit"/>



Additionally, form controls belong alongside other markup in the visible portion of the document, which means the <body> element in XHTML:


  <p>Enter your credit card number below</p>

  <xforms:input ref="cc">

    <xforms:label>Credit Card:</xforms:label>







Initially, HTML forms didn't associate any kind of field-level label with form controls, except for physically positioning the labels near the controls, which was especially difficult for non-visual browsers to interpret. Later versions added an optional label wrapper, but this technique never gained widespread usage. Now in XForms, every form control element has a required label child element, which contains the associated label.

Upon submit, the XForms Processor would deliver serialized instance data -- which looks something like



-- where the element name is determined by the binding expression attached to the input element. In more advanced settings, separate instance data can define arbitrarily complex XML structures processed through XForms.

What It Means

What does the future hold for XForms? One certainty is that connected devices are becoming more diverse than ever, appearing in all shapes and sizes. Web forms no longer lead sheltered lives on the desktop. By offering a more flexible, device-independent platform, XForms will provide interactivity on such devices.

Most organizations now have substantial investments in XML. Since XForms technology reads and writes XML instance data, it enables existing investments to be leveraged as building blocks in a larger system more smoothly than with ordinary XHTML forms. Additionally, Web Services (or the Semantic Web, depending on your upbringing) will increase the amount of information interchange over the Web, which will in turn increase the need for information to be entered -- through XForms.

Those who have struggled with traditional forms and associated scripting will appreciate the consistent set of form controls and declarative actions in the specification, as well as the powerful and familiar XSLT-like processing model. Calculations, validations, and business logic will also be expressible without scripts.

Updated forms are one of the major changes in XHTML 2.0, the most significant change to HTML since its conception in 1993. Developers and users alike are looking forward to the final W3C Recommendation for XForms.

For More Information

The primary source for information on XForms is the www-forms mailing list. To subscribe, send an email to www-forms@w3.org with the word "subscribe" in the subject line (include the word "unsubscribe" if you want to unsubscribe). The archive for the list is also accessible online.

To play with the latest XForms specification, you can use the latest published Schema, or try out one of the following early implementations:

The open source X-Smiles browser supports an impressive array of standards, including XForms, SVG, SMIL, and XSL formatting objects. E-XMLMedia has developed a Java applet-based version, which is available as a commercial product, with an evaluation version available upon request. Additionally, Mozquito is working on a Flash implementation, with details posted on an editable weblog done in XForms. (Warning: this link requires an XForms browser) More implementations are coming online soon.

1 to 18 of 18
  1. christmas lights installation los angeles 310 295 0153
    2009-11-21 12:18:59 herscko
  2. XForms Available as XSLTForms
    2009-10-04 04:05:10 Dominique.Rabeuf
  3. Building XForms scripts?
    2005-06-07 14:04:17 nikkys
  4. days-from-date()
    2004-12-02 14:54:54 kickiki26
  5. XForms Institute
    2004-02-04 10:24:34 Micah Dubinko
  6. Why header information?
    2003-01-17 14:03:19 Michael Long
  7. XForms not yet ready
    2002-11-19 01:56:42 Stephan Portmann
  8. XLM forms Indexing
    2002-11-12 11:27:13 Manisha Sheth
  9. Ubiquitous forms or not?
    2002-11-08 17:34:43 Steven Punte
  10. what modules
    2002-10-07 22:39:35 suad al-borno
  11. XForms & Apache Cocoon
    2002-09-21 21:29:29 Ivelin Ivanov
  12. XFORMS and Schema's
    2002-09-11 07:52:41 Marc van der Zee
  13. what about XUL?
    2002-02-04 11:13:52 marcelo alfaro
  14. XForm to WML
    2001-12-03 16:47:03 Krisnasamy Arumugam
  15. XForms vs. XFA and XFDL
    2001-11-30 08:40:36 Sébastien Landeau
  16. Lets get real...
    2001-10-01 12:14:27 tony r
  17. XForms very useful for web apps
    2001-09-18 13:19:33 Jan Dvorak
  18. XForms
    2001-09-06 03:10:39 Enrico Granata
1 to 18 of 18