Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 3 min read

Support

Motivation

Sometimes all you need to do is to put a nice user friendly form that edits a single static XML file. In this case a static file is any file where you know the exact pathname to the file when the form is created and you know that the file name will never change. This is the case when an application has a configuration file in a known location (either absolute or fixed relative to the XForm).

If this is a local file on your hard drive this is very easy to do just by using get and put operations and either absolute path names to the file or relative path names to the directory that the form is located.

XForms also allows a user to read data into a form using a HTTP get and to write data from a file using HTTP put operations using a remote web server. Just make sure you enable put operations on your web server and that the file you are putting is writeable This means you will need to do a chmod +w if it is a UNIX file.

Sample Program

xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Submission with get and put

id="data-instance" src="data.xml" xmlns="" />
id="read-from-file" method="get"
action="data.xml" replace="instance" instance="data-instance" />
id="save-to-file" method="put"
action="data.xml" replace="instance" instance="data-instance" />

Demonstration of using XForms to get and put data to local file using the submission element.

ref="Element1">
Elementu 1:

/>
ref="Element2">
Elementul 2:

/>
ref="Element3">
Elementuul 3:
/>

submission="read-from-file">
Reload

submission="save-to-file">
Save

Sample data.xml Instance File

The following file is read into memory (from the same folder that the form was executed in) when the form is loaded into the browser. This file is written to the disk when the save button is pressed. The reload button will reload the file into the browser.

One
Two
Three

Discussion

Note that this form is not applicable when the form data is in a file name that is selected at run time. This is because the src attribute in instance is not dynamic. You can not use an XPath expression in the src attribute.

Here is an example of how files could be dynamically loaded in XForms 1.1:

id="read-from-file" method="get" replace="instance" instance="data-instance">
value="instance('my-instance')/FileNameSetByUpload"/>

Note that if this was the case, any form from a nefarious web site might be able to look for a known files or suspicious such as my-passwords.doc and upload them without your consent. This restriction may be eased if the "resource" attribute (part of the XForms 1.1 draft) gets implemented.

References

XForms 1.1 standard on submit resource - This allows the resource path to be dynamically created based on instance data.

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Get each new page of

XForms

Following means one email when a page is added, nothing when a page changes.

Following means one email when a page is added, nothing when a page changes.

Comments

Spinner Logo

Next in XForms

CC BY-SA 4.0
This example will show you how to save intermediate form data to a local disk. Sometimes long forms take a while to fill out. You would like to allow users to fill out part of a form, log off, and resume their form when they return. Sometimes this intermediate data can be used as a default template
CC BY-SA 4.0
XForms, Tri-Document Loading
CC BY-SA 4.0
The first tab will be for people and the second will be for organizations. ## Screen Image ![Entity Selector Control. Note that only the person names that contain the string 'John' are displayed]( Entity Selector Control. Note that only the person names that contain the string 'John' are displayed (
CC BY-SA 4.0
Note that you **must** have the **xf** prefix on the attribute. This is different then the usual process. Note: This example does not run under the FireFox 0.6 or the 0.7 extension. See [Bug 280368]( for details.
CC BY-SA 4.0
When the user types in the input field we will narrow down the choices using an XPath expression in the repeat **xf:nodeset** attribute. The XPath expression will only match items that begin with specific characters in the xf:input field. ## Screen Images ## Link to working XForms application [Repea
CC BY-SA 4.0
XForms, Inline Repeats