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

advertisement

Interactive Web Services with XForms
by Micah Dubinko | Pages: 1, 2

XForms in Two Easy Steps

Form authoring can be thought of as a two step process: first, create the underlying form definition, called the "XForms Model"; second, create the user interface mapped the the XForms Model. A huge benefit of this design is that existing XML and Schema resources can be directly used with forms.

Step one is to create the XForms Model. In an XHTML containing document, this goes in the head section:

<xforms:model>
  <xforms:instance xlink:href="http://www.example.com/getInstance"/>
  <xforms:schema xlink:href="CCInfo-Schema.xsd"/>
  <xforms:submitInfo action="http://www.example.com/submitInstance"/>
</xforms:model>

As short as this is, it defines a complete form, though without any means for user interaction (that's the next step). The XForms Processor looks at the initial instance data and constraints found in the XML Schema to initialize the XForms Model. A submitInfo section gives directions (all defaulted here) for writing out the submitted instance data and then where to submit it.

Step two is to attach a user interface, keeping in mind the range of possible target devices (desktop browsers, cell phones, voice browsers, paper, and so on). In an XHTML containing document, this goes in the body section:

<xforms:output ref="i:FullName"/>

<xforms:selectOne ref="i:CardType" selectUI="radioGroup">
  <xforms:caption>Card Type</xforms:caption>
  <xforms:choices>
    <xforms:item>
      <xforms:caption>MasterCard</xform:caption>
      <xforms:value>MC</xforms:value>
    </xforms:item>
    <xforms:item>
      <xforms:caption>Visa</xforms:caption>
      <xforms:value>V</xforms:value>
    </xforms:item>
  </xforms:choices>
</xforms:selectOne>

<xforms:secret ref="i:Number">
  <xforms:caption>Card Number</xforms:caption>
</xforms:secret>

<xforms:input ref="i:Exp">
  <xforms:caption>Expiration Date</xforms:caption>
</xforms:input>

(Complete XHTML+XForms document)

Here there are four form controls defined:

  1. An <output> form control to display (but disallow changing) the User's full name.
  2. A <selectOne> form control to choose the card type from a list. A user interface hint is included to treat it like a radio button group.
  3. A <secret> form control (bound to an xsd:decimal datatype from the Schema) to allow the entry of a credit card number without rendering the digits as they are typed.
  4. An <input> form control (bound to an xsd:gYearMonth from the Schema) to allow the entry of the expiration date.

The ref attributes on each form control, which contain XPath location paths, serve as a connection between the form controls and a data location in the instance data.

Compared to the XHTML discussed earlier, getting XML data in and out of forms is cleaner and simpler. And a new set of form controls provides greater functionality across a wider set of devices of all shapes and sizes. Form building is generally an iterative process. From this foundation, additional constraints, validations, and usability enhancements can be added.

Conclusion

Since its inception the Web developed as a rich source of information trapped in a format meant primarily for human consumption. This led to a raft of retyping, screen-scraping, and poorly integrated applications. Recently, the focus has shifted towards automatically discoverable, self-describing modular applications. XForms technology is the bridge between these two worlds.

Authoring XForms is simple, taking only two steps, and you can reuse Schemas and instance data already available in a web services environment.

The main issue at this point is the lack of conforming XForms Processors with which to utilize forms on the client side. The XForms specification is still a moving target, still in the "Working Draft" phase. The XForms Working Group is actively seeking feedback and implementation experience. In the short term, server-side tools that transform XForms into browser-digestable HTML are a good solution. Looking farther out, next-generation networked devices are lining up support for XForms. Who knows, maybe even someday browsers will support XForms.

In the end, information for, from, and about people is what's interesting. New tools on the horizon make this easier than ever.



1 to 2 of 2
  1. Modulairzing XHTML 2.0 doc and XForms
    2003-07-03 06:20:08 John Sasso
  2. xforms
    2001-11-18 23:54:57 kim ju-young
1 to 2 of 2