A profound change is likely about to shake up your world if you’re a web developer, one that I suspect will make the recent efforts in the AJAX space pale in comparison as far as its effect. Very quietly, over the last few weeks, the Mozilla team has been upgrading their XForms capabilities through the use of an XForms extension. It requires that you are running Firefox 1.5.0.1 or above, or Seamonkey 1.0 or above, but frankly, there are very few reasons for you not to be at this stage if you’re a Firefox or Seamonkey fan.
More than two years ago, I wrote a piece in my blog with the name “Why XForms Matter” that examined this technology in some detail, but at the time, the level of support for XForms was rather depressingly thin. A standard formalized in 2003, the XForms 1.0 Recommendation offered up an intriguing vision - an XML based format for the deployment of form fields both within XHTML documents and within other XML environments (such as SVG, the Scalable Vector Graphics language) that would make it possible to make a surprisingly powerful rich client that didn’t have to be extraordinarily heavy in terms of memory footprint, processing power, or speed. What’s more, as a W3C standard, it could be deployed with no royalty costs, could be implemented on a wide variety of platforms in implementations that only had to be compliant to the standards, not to any development language, and couldn’t be held hostage to a company’s need to change their operating environment every time sales figures lagged for the quarter.
The response to this technology, on the other hand, has been fragmented at best, though I have to admit that I should have seen that coming. I’ll get to why in a bit. For now, I want to talk a little bit about the state of the web in 2006. The state of the art in 2006 can be described in four letters A-J-A-X. If you understand AJAX, you have essentially written your meal ticket for the next couple of years. Indeed, right now we are in that state of affairs that I had a feeling we’d be facing right now - there’s a huge demand for AJAX programmers, and a surprising dearth of skilled practitioners. Given that AJAX is only Javascript, XML and a bit of socket programming, you’d think that this demand should have been filled pretty readily … but its not really all that simple.
AJAX programming represents a fairly radical jump if you’re used to traditional server-side applications, though if you were playing with Macromedia Director or Flash nearly a decade ago, you’d intrinsically recognize what’s going on here (indeed, note to hiring managers - get good Flash programmers if you’re looking for people who understand AJAX … they’ve been doing it for years and years). The idea behind AJAX is that we are shifting away from the model where the server becomes responsible for the presentation and state management of an application and toward the model where the purpose of the server is to dish up structured data content. Not only does it speed up your applications by an order of magnitude because you’re not waiting for the server to spit content out to you fast enough, but it also means that you can actually handle most of your state management there on the client as if it was a form, something that should be familiar to VB developers worldwide.
However, there are some intrinsic problems with this model. One of the first is the fact that Javascript is nowhere near as easy as it seemed a few years ago. It’s actually always been a fairly powerful and complex language, because it is a language that treats functions as objects, treats instances of functions as objects, and by automagically hiding the type conversion from the developer makes it possible to start concentrating on some fairly complex behaviors that usually were well outside of the feasibility stack because too much time was spent getting “Hello, World” working.
AJAX also tends to push a fairly heretical idea onto the plate - the notion that you can send Javascript objects up and down a pipe in some serialized fashion and have them get instantiated in some other context. Now, personally, the idea of doing this gives me the willies … because it opens up the potential for serious mischief, not least of all, but it is also a powerful modality for programming by moving objects around as if they were free-floating entities in a distributed sea. To me, it also tends to blur a critical boundary for me concerning the point at which point code becomes data, but it may be that this is because I tend to see Javascript as a lightweight imperative framework that takes the declarative code of XML and “does” things with it.
However, there’s another problem with AJAX — as a language, Javascript is not in fact terribly efficient as either a means of representing complex data structures or of providing a consistent internal framework for manipulating those data structures. Even with such technologies as E4X, there’s still a tremendous degree of adhocracy going on right now that makes it difficult to do one of the things that Javascript was, ironically, intended to do well - handle form content, especially in distributed environments.
I’ve been working a lot lately with mixed XML/Javascript frameworks, and curiously enough, the more complex the applications become, the more that they in fact begin to resemble … well, XForms. You have one or more XML data stores that can represent anything from a personal schema to a description for an entire set. You have a series of bindings that determine the boundaries and secondary processing of data between components, you have event notifiers that get passed from object to object in a subscription oriented framework. All of these facets, and more, are critical pieces of the XForms space.
In point of fact, you can create some incredibly rich “web experience” applications that are mixed XHTML and XForms, and can do so in a remarkably short amount of time. These are not simply empty text fields that you lay out as you do with HTML >input< elements - XForms bears about as much resemblance to HTML forms as a Bengal tiger has to a ferret. If you go back far enough you’ll probably find that they share a common ancestor (they do, in fact - a weasel-like tree dweller called a Miacis, from about 50 million years ago), but in many ways XForms is more the harbinger of a new web development architecture where the application (the web page) holds a model that either populates or is populated by various XML form elements. When the model changes, so do the form element contents. When the form elements change, so does the model. This is handled automagically in the background, using the power of XPath expressions and data bindings to create sophisticated applications.
So how does this differ from the “traditional” AJAX application? The difference comes from the nature of that automagic, which is far from being either automatic or magical in the latter context. In an AJAX application, you explicitly sit on the page load tag to grab an XML (or related) resource from the server, creating an asynchronous call that will update an explicitly defined model, then write more code that will walk through that XML model and either pass it to an XSLT transformation or run it through more DOM manipulation code in order to explicily populate the fields in question in the web page (any more explicit and it would require an X rating). You can cut this code down considerably with some carefully coded libraries, but these libraries add to the overhead of both loading and maintaining the page, sometimes significantly, and if they are not well written can also add a considerable burden to the debugging department.
On the other hand, an XForms like architecture defines XML data models, constraints, and bindings explicitly as rules given within an a declarative XML format. This declarative form works in a manner similar to that of an Excel spreadsheet. In Excel, for instance, you define both blocks that hold initial data then you have functional blocks that perform calculations either upon the initial data or a previously defined functional block. What you end up with in this kind of declarative “program” is an application where the “answer” may in fact be a lot of different pieces of information, where the only action involves the changing of one or more initial values, and where constraints will at a minimum prevent you from entering erroneous data.
Whether talking about spreadsheets or XForms, the one dominating factor in both cases in their development is the recognition that you are creating such a form in its entirety, at every single point within the application process itself. This is a fairly subtle concept, but its an important one. When you create an imperative script, at any given point in the process that script will be incomplete, perhaps to the point of being unrunnable. This means that most development requires that you create fairly complex modules, run (or compile) them, then spend time trying to figure out why you’re not getting any answer coming from out of the black box. It necessitates at the beginning having a comprehensive idea about what pieces you will need to construct the application, and so places a premium on planning in environments where planning and design budgets are usually pushed to the absolutely minimum.
In a declarative model such as XForms, however, so long as your syntactical structures are intact (i.e., so long as you have clearly defined well-formedness) your model will run. You CAN, of course, design forms that do not check for valid data, so there is no guarantee with XForms (or Excel for that matter) that your model will return anything meaningful. In other words, garbage in - garbage out still applies. However, introducing constraints in such an application is also not hard to do, making it much more difficult to insert garbage in the first place.
However, it also means that when you’re dealing with declarative forms such as this, you DO still need to understand the model (indeed, to a certain extent, you need to understand the model better), but one of the things that I’ve found over the years is that models very seldom spring into life fully-formed. Indeed, its perhaps more accurate to say that the model for any form of even reasonably complex interface tends to emerge throughout out the lifecycle of the process. I believe that XForms makes this process easier, because it becomes MUCH easier to track (and change) dependencies in an XForms based model than it does to change such dependencies in either object oriented code (refactoring) or scripting (wholesale panicking).
XForms is not a complete solution, though its usually close to it. Sometimes you need to write extensions, and many XForms engines have mechanisms for extending the default XPath implementation in various ways. Additionally occasionally you will run into situations where you want to replace the default XForms standard controls (for example, turning an <xf:output> element into an image display control). The XForms model in this case works very well with other binding languages (such as Mozilla’s XUL or the SVG sXBL binding language), as I will be showing in a subsequent column on XForms (highlighting a non-trivial XForms application in Mozilla Firefox).
However, for all that, the XForms idiom is surprisingly robust. For instance, if you wanted to create multiple author entries in a papers submission form in HTML, you would have to create entries for each author grouping in turn. In XHTML+XForms, on the other hand, you’d need to do only two things: build the model of the content you’re wanting to display:
<xf:model id="data">
<xf:instance>
<d:submission>
<d:author>
<d:firstname>Kurt</d:firstname>
<d:surname>Cagle</d:surname>
<d:middleinitial>A</d:middleinitial>
<d:affiliation>Metaphorical Web</d:affiliation>
<d:email>kurt.cagle@gmail.com</d:email>
<d:website>http://www.understandingxml.com</d:website>
</d:author>
<d:author>
<d:firstname>James</d:firstname>
<d:surname>Kirk</d:surname>
<d:middleinitial>T</d:middleinitial>
<d:affiliation>Starfleet</d:affiliation>
<d:email>james.kirk@starfleet.mil</d:email>
</d:author>
<d:author>
<d:firstname>Cecilia</d:firstname>
<d:surname>Jones</d:surname>
<d:middleinitial>E.A.</d:middleinitial>
<d:affiliation>University of Victoria</d:affiliation>
<d:email>cecejones@uvic.edu.ca</d:email>
<d:website>http://www.cecesite.com</d:website>
</d:author>
</d:submission>
</xf:instance>
</xf:model>
and use an XForms repeat block to reference this:
<xf:repeat nodeset="/d:submission/d:author">
<fieldset>
<legend>Author</legend>
<div>
<xf:input ref="d:firstname">
<xf:label>First Name: </xf:label>
</xf:input>
<xf:input ref="d:middleinitial">
<xf:label>MI: </xf:label>
</xf:input>
<xf:input ref="d:surname">
<xf:label>Surname: </xf:label>
</xf:input>
</div>
</fieldset>
</xf:repeat>
The beauty of this as well is that as you change the values of the respective input fields, the XML data model will automatically be kept in sync - you do not need to write complex iterating code to do it. You can easily add or remove entries in the same manner (code which I’ll show in my next XForms post) and do so with minimal (and in most cases no) additional scripting.
The combination of XForms, XHTML, CSS, SVG, XBL-like bindings and the like can make for a wide variety of applications. Certainly, XForms could easily replace tabular presentation forms, but could just as easily be used for building rich slide-show applications, multipane websites (complete with tabs, side tabs, button sets and related controls), multipage wizards, even game environments.
One reason for this diversity of form comes from the fact that the language works with abstract components that have known programmatic interfaces but not necessarily known user interfaces. I’ve heard, in various circles, some mocking of such abstractions, but one of the things that I keep rediscovering is that the set so covered actually works quite well in hitting more than 99% of all potential components, either by themselves or in aggregate. A tabset, a button bar, radio buttons and drop-down selectors are all instances of a <selectone> component in that they all handle the same task (choosing one item from a set and performing an action based upon that selection) albeit with different skins.
In the ensuing couple of weeks, I will be looking at two or three such XForms examples in detail within Firefox. I hope to keep them relatively simple but meaningful (there are four or five calculator objects out there which are cool to look at but which are too complicated to use as pedagogical examples, for instance). It’s a technology worth coming back to, especially in this day and age of increased focus on the browser. It can help tame some of the thornier AJAX programming issues, and I suspect in the end will represent the next major leap in web technologies.
Given the rising proliferation of “component toolkits”, I see a coming period where everyone’s going to be trying to get THEIR component interfaces accepted as the “standard” ones. The XForms components actually handle almost all of these cases, provides a standard, open, non-proprietary solution that suffers only from lack of education and exposure, and with its presence now in Mozilla (and numerous versions available in IE, including both ActiveX and pure Javascript versions) I see XForms poised to become the de facto forms technology within the browser world.
Kurt Cagle is an author and columnist specializing in XML and Web technologies. He lives in Victoria, British Columbia.


fghjfghjfhj
Please don't take this the wrong way. I simply don't understand XForms. Sure I have negative opinions of XML, but setting those aside, is XFroms as replacement for HTML forms:
I also don't understand its relationship to AJAX. Can XForms handle asynchronous retrival of data?
Kurt, great article! But while client-side XForms implementations have their place, you cannot propose the XForms programming model as a practical alternative to the low-level Ajax programming model without looking at how it is possible to forego native client implementations such as Firefox or plugins such as FormsPlayer. It would be only fair if you looked at Ajax-based XForms implementation such as the open source Orbeon PresentationServer (http://www.orbeon.com/).
Erik,
I don't necessarily see AJAX as an alternative to XForms. Rather, I see AJAX as being a step towards XForms - as Orbeon (which is a wonderful technology, btw) illustrates, you can create a very effective XForms technology around AJAX. Indeed, while I haven't looked at the source yet on it, I suspect that the low level Mozilla implementation likely is calling AJAX-like code in the background.
XForms is, like most XML technologies, an abstraction layer, not an implementation layer. Whether or not its the best abstraction layer will likely be debated until the cows come home, but for at least one domain - form-like content, it works very well. There are no doubt many places where an AJAX-centric solution that doesn't involve XForms makes sense ... however, given that XForms is vastly underutilized for what it could be doing, it doesn't hurt to at least raise the awareness of the technology a bit
Nice article!
Since, apparently at least, the FormsPlayer version of XForms can interact with compiled code, this may be away to use XForms directly with the programming language of one's choice.
Kurt, wonderful to to hear you write of the power in XForms. I have been waiting for something like XForms to catch on since 2000 when I first started studying XML. XML is the rich way to describe document style data, but a massive amount of that data needs to come from user entry. XForms is the tool to get the data from the average Joe user into the desired XML schema efficiently. How wonderful to be able to quickly build intelligent forms to collect structured data in any schema you want (or create) and forward that to the server, or even better, save it on your hard drive and forward it when you are finished/ready.
Expense reports, workplace accident reports, blog entries, calendar appointments, purchase orders, invoices, income tax reports, school tests, contact info, all possible now but XForms makes it all so much cleaner and easier to build and manage.
How wonderful to have a cache of XForms on my laptop that allows me to fill out tax reports, blog entries, expense reports while offline, save to disk, then submit them to the server the next morning at the office!
Kudos to Allan Beaufour and his mates working on the Mozilla extension, hopefully it will be grafted into the main Mozilla code in the near future.
Kurt, in fact I agree 100% with your statements! I believe there are two main facets to the XForms question today: implementations, and raising the awareness of the XForms technology. In both cases, the Ajax story is relevant.
Kurt,
Once again a stunning article!
I think the key point that you make--and which is widely missed and unfortunately not very well promoted from within the XForms community--is that XForms is an incredible abstraction layer.
This means two things; first, even if you convert XForms to a combination of HTML and script as Erik describes (I think they call that 'Ajax' nowadays, don't they...;) it is still a lot easier to manage the original XForm than it is to manage script built on an Ajax library. As you say, if you have a way of converting an XForms select1 to HTML+JS and you have a way of converting a switch/case combination to HTML+JS, then you can create tabbed dialog boxes without writing any more HTML+JS...you just combine the widgets in new ways.
And the second thing--which is again something you point out extremely well--is that XForms is a *standard* way to express things. Currently, when using different Ajax libraries, we have any number of different ways of getting notification that our data has been sent, or new data received. However, with XForms, regardless of what platform you run on (Ajax or Java, Firefox or IE) you will always get the "xforms-submit-done" event.
Ajax unfortunately doesn't even seem to have a standard eventing mechanism, never mind standard event names, which means that you can't even use different widgets from different libraries together; imagine the development power that would be unleashed if everyone who is developing widgets for Ajax was developing them in a standard way? Even if they still used script, if we had standard event names (and a standard eventing architecture) and perhaps a standard document structure (perhaps XBL) then all this energy could be reused over and over, and built on in ways that we haven't even begun to think about. This is the possibility that using standards like XForms, XML Events, and so on, holds out.
Still, it's important to get the balance right--the energy and sheer ingenuity that has gone into the Ajax wave has made people open to the ideas expressed by XForms, and if XForms does have any success in the next few years, it will be thanks to this atmosphere of experimentation. It makes this an exciting time for software developement!
Finally, I hope you don't mind, but I'll post a couple of links to articles on my blog that discuss some of these issues, and so may be of interest to readers of your article. One is on the idea of 'patterns' in XForms--XForms as an executable pattern language and is part of a debate I had on the subject of declarative mark-up versus script, with Bill McCoy of Adobe. Another relates to a debate that ran on one of the SVG lists, concerning scripting versus abstracting functionality out into components that are bound in at run-time (again declaratively): Loosely couple objects and declarative programming.
And finally, on why XForms is part of the Ajax family, even if it's most likely to leave home and go on to greater things (perhaps visiting occassionally to do its laundary): XForms and 'Ajax languages'.
Best regards,
Mark
Mark Birbeck
CEO
x-port.net
http://www.formsPlayer.com/
Exactly! Great stuff!
A small correction: it is , not .
A couple of stylistic points:
- you can write , since the context is by default the root element of the instance.
- rather than the , you can use:
Author
...
(Sorry, my markup got eaten; try again)
Exactly! Great stuff!
A small correction: it is <select1>, not <selectone>.
A couple of stylistic points:
- you can write <xf:repeat ref="d:author">, since the context is by default the root element of the instance.
- rather than the <fieldset><legend><div>, you can use:
<xf:group>
<xf:label>Author</xf:label>
<xf:input ref="d:firstname">...
When you say "the more complex the applications become, the more that they in fact begin to resemble … well, XForms" it really resonates with me. A few years back I designed a dreadfully complex system to edit XML documents via a web interface using Javascript. The cacophony of hard-coded rules and DHTML tricks to repeat and delete elements was mind-boggling. The XForms specification was in review at the time, but I knew my approach was a necessary evil.
Today I'm redesigning the old system with XForms, and while it isn't a walk in the park, I have a degree of confidence that the data model and logic bears resemblance to the data. I also believe XForms can be supported and maintained by another person. Keep up the good articles.
Great Article! Over the past two years I've been applying the work we did on XForms in my work at Xerox with Intranet applications, and it's been quite beneficial. It's been really great having a field of suppliers vying to provide me with what I need. Firefox is a great addition to this area, and one that I hope will jumpstart XForms adoption on the Internet.
Nice article. The problem with XForms is that no matter how nice a concept it is, until the majority of browser are distributed with it (and with it enabled) by default, it's really not ready for prime time. Since I have to develop web applications with all potential users in mind, I can't assume that someone's going to have an XForms imlementation in their browser. I mean I still have to support IE5.0 in my applications. It's one thing to be interested in the latest and greates thing to come down the pike, but it's entirely another to be in a position where you can use it for a client's (public-facing) web site. Don't get me wrong, I'd -love- to be able to use XForms. It's just that for the next few years, it's not likely to happen.
This is all great but what we can do if today Xforms aren't yet a full functional cross-browser thing, i wanted to start using them because of great functionality one year ago, but there you have lot of Xforms players jonglery and trickery before you get them work, not to mention incompatibility problems.... so Where Xforms will be alive i want to start using them finally (uh i find me saying same thing years ago)...
Very interesting.
great site
53c04118df hi, i`m from india, and i has been very hart by you site)))
Interesting comments.. :D
The perfect chicken soup recipe
Think big, crisp, and gloriously browned when you want a bird that reigns
supreme at the table Size matters. Position doesn't. That's what a palate-weary ...
Managed Hosting, Colocation and Data Center Services by victoryushchenkonashpresudent ...
The Forms Working Group is comprised of W3C members and invited experts. The Working Group meets weekly by phone. Face to face meetings occur roughly every 3 months and are hosted by member organizations. We are especially interested in people with a rich experience in developing Web forms and supporting tools
Son
I took some of your article for translation into dutch. If is for a Dutch learning wiki It is part of a AJAX learning path to master the programming code. Is this ok?
Interesting article. I have put the link on my blog.
I also don't understand its relationship to AJAX. Can XForms handle asynchronous retrival of data?
Hi I am not able to view any of the elements like submit buttons in spite of adding plug-in/add-ons. Please advice
Thanks