Background and Motivation
Since K&R wrote the first book on C programming, it has become tradition for programming books to begin with a "Hello World" program. Running this program will indicate if you have XForms installed correctly.
Here is a sample "hello world" program in XForms. It uses one input, one variable in the model, and one output. You should be able to just copy and paste the text into a program such as Notepad and save it to a file such as hello.htm. This will tell you if you have the Firefox or other browser extension installed correctly.
(Note that this is only a .jpg and NOT an actual form!)
Link to Working Example
To run this program, just copy the following text into a file "hello.xhtml" and open it with your web browser with the appropriate XForms extension loaded.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"> <head> <title>Hello World in XForms</title> <xf:model> <xf:instance xmlns=""> <data> <PersonGivenName/> </data> </xf:instance> </xf:model> </head> <body> <p>Type your first name in the input box. <br/> If you are running XForms, the output should be displayed in the output area.</p> <xf:input ref="PersonGivenName" incremental="true"> <xf:label>Please enter your first name: </xf:label> </xf:input> <br /> <xf:output value="concat('Hello ', PersonGivenName, '. We hope you like XForms!')"> <xf:label>Output: </xf:label> </xf:output> </body> </html>
If this program does not work, you may not have the extension or plug-in installed in your browser.
For help see Installing XForms in FireFox.
Note that if you have the NoScript Firefox extension installed, you may need to configure NoScript to allow scripts from the location from which you are loading HelloWorld.
Also note, in Firefox the file has to be saved with a xhtml or xml extension. A file with a .html exension won't show the XForms.
Note that the file looks much like a standard HTML file with a few exceptions.
- there is a namespace declaration at the beginning of the file and there are two elements with a
xf:prefix in front of them.
- there is something called a model inside the HTML
- There are some new elements:
The two important lines are:
<xf:input ref="PersonGivenName" incremental="true"/>
<xf:output value="concat('Hello ', PersonGivenName, '. We hope you like XForms!')"/>
As the user types, this line takes the input that the user types in and copies it to the instance variable "PersonGivenName". Each time you type a character this program updates the output and using the XPath
concat() function to wrap the string "Hello " in front of the name and the string ". We hope you like XForms!" after it.
Try changing the input attribute incremental from:
The output should update only after you enter "Tab" or press the "Enter" (Return) key.