Hub Nexus
Aggiornato

AutoreAncora senza autorePrendila in carico

Vedi qualcosa da migliorare? Proponi una modifica.

Sostegno

In XForms · pagina 86 di 137

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.

In queste pubblicazioniXForms

LingueEnglish

Licenza: CC BY-SA 4.0 · Tratto da en.wikibooks.org

1

0

0

0

Spinner Logo

Commenti

Spinner Logo
Versione: 2CC0 1.0 — public domain
The runaway star that left the Tarantula Nebula
Versione: 2CC0 1.0 — public domain
The Blackwell School, where segregation had no law behind it
Versione: 2CC0 1.0 — public domain
The Eagle Nebula, seen in the infrared
Versione: 2CC0 1.0 — public domain
The house where the Equal Rights Amendment was written
Versione: 2CC0 1.0 — public domain
The Aleutians, the forgotten front of the Second World War
Versione: 2CC0 1.0 — public domain
The Cosmic Cliffs are not cliffs