Happy anniversary, XForms

The other day I received an e-mail from a friend who has been expanding his Web development skills with a few independent learning projects. A man of few words, his message read as follows: “Further to my education in XML, what’s the easiest way to get changes back into the document?”

The question makes a lot of sense given that up until this point he had been asking me how to do things with stylesheets — how to format existing XML data for presentation. With previous experience in HTML, this stuff was a reasonable extension of his knowledge. It was only a matter of time before he wanted to know how he could allow the user to change the underlying data.

My friend probably didn’t expect that this question would place him at the edge of a diving board — for his learning to progress he would have to plunge into the deep end of server-side programming.

This highlights the shortcomings of today’s Web browsers. Although they can present XML in a highly dynamic fashion, they aren’t nearly as good at capturing/recapturing it. Content “round tripping” is not supported by XML-based languages alone — this requires program code. For a relatively long time we’ve been able to display forms in a Web browser, but there’s a huge functional gap when it comes to capturing user input as XML instance data. XForms is a W3C recommendation that aims to help bridge this gap.

Although XForms still doesn’t provide a means of actually writing to a file on the server, it will send form data to the server as an XML document. This is a significant step forward, because it is no longer necessary to write custom code for mapping the name/value pairs submitted by traditional HTML forms to XML elements.

An XForms implementation will provide a number of perhaps even more significant capabilities, such as device independence, Schema-based form validation, and richer form control elements, to name a few.

If it sounds too good to be true, your skepticism is justified. Current versions of the major browsers don’t support XForms natively. However, there are plugins available, such as formsPlayer (www.formsplayer.com) for IE 6. Mozilla has an XForms development project underway to bring support to their browser.

My code example was created to work using formsPlayer. I started out looking at the “Schema-Based Form” example on the forms-Player site, which ensures that an entered value matches the specified data type. I decided to recreate this functionality in a form that would validate two entered integers, but also add them together on the fly using an XPath expression and display the result.

The necessary element is a pretty good indicator that this implementation is a bit clumsy, but hopefully you can see the potential power of an XML-aware Web form.

The inline CSS controls the appearance of alert messages — they are not visible unless the corresponding field fails validation.

Coincidentally, the W3C XForms Recommendation document is dated exactly one year ago — as of me this writing. This first anniversary is all the excuse I need to go pour myself a glass of Scotch. Cheers!

<html xmlns=”http://www.w3.org/1999/xhtml” xmlns:

xforms=”http://www.w3.org/2002/xforms”>

FormsPlayer has failed to load! Please check your installation.

.valid xforms\:alert { display: none;

}

.invalid xforms\:alert { display: block;

}

First Number:

Please enter a number.

Second Number:

Please enter a number.

Total:

Would you recommend this article?

Share

Thanks for taking the time to let us know what you think of this article!
We'd love to hear your opinion about this or any other story you read in our publication.


Jim Love, Chief Content Officer, IT World Canada

Featured Download

Featured Articles

Cybersecurity in 2024: Priorities and challenges for Canadian organizations 

By Derek Manky As predictions for 2024 point to the continued expansion...

Survey shows generative AI is a top priority for Canadian corporate leaders.

Leaders are devoting significant budget to generative AI for 2024 Canadian corporate...

Related Tech News

Tech Jobs

Our experienced team of journalists and bloggers bring you engaging in-depth interviews, videos and content targeted to IT professionals and line-of-business executives.

Tech Companies Hiring Right Now