Ser du något att förbättra? Föreslå en ändring.
Motivation
The upload element allows you to select a file from the file system using your operating system's "Browse" user interface. This file can then be transferred to the file server that the web form resides.
Screen Image
Here is a screen image of the Firefox XForms extension upload control after the C:\tmp\Foo.xml file was selected:
(Image: Eddy Chaverra, CC BY-SA 3.0)
The XForms upload Element
ref="XPathExpression" mediatype="text/xml">
ref="XPathExpression" />
ref="XPathExpression" />
Sample Program
This sample program has a single instance variable called "File". At the end of the select this variable is set to the path-name of the file you just selected.
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
xmlns="">
xsi:type="xs:anyURI"/>
ref="/Data/File">
file:///C:/tmp/*.xml
text/xml
ref="/Data/File">
File:
Discussion
At the time of this writing, there is little documentation on how the upload control works. The screen shot above was taken from the Firefox XForms 0.8 running on Firefox 3 implementation. Note that the file name appears twice in the control itself. This may not be the future behavior. This may be that the filename and mediatype text inside the control are being displayed. There is no documentation yet on how to disable the clear trigger.
There is not yet documentation on how to upload instance data into the model using the upload control. Right now instance data must be hard-coded into the src attribute of an instance.
The following loads both an image and a URI.
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
xmlns="">
xsi:type="xs:base64Binary"/>
xsi:type="xs:anyURI"/>
id="save" action="http://xformstest.org/cgi-bin/showinstance.sh" method="post"/>
ref="image">
Upload Photo:
ref="uri">
Upload File:
file:///C:/tmp/*.xml
text/xml
ref="image">
image:
ref="uri">
uri:
submission="save">
Save
Uploading Binary Files
Any file type such as an image or XML file can be converted to a 64bit encoded file, stored in the instance and then transmitted to the server inside of a POST. On the server the file can be converted back to a string or binary.
Sample Echo With Binary to String Unencoding
The following is a simple echo script written in XQuery that echos back the binary file in XML. It is an XQuery script
that uses a binary-to-string conversion function. This takes a file of type xs:base64binary and returns a string
representation of the file. The data to be returned is in the element with the element name "xml-base64".
xquery version "1.0";
declare option exist:serialize "method=xml media-type=text/xml indent=yes";
(: this gets the data from the HTTP POST :)
let $post-data := request:get-data()
(: this converts the base-64 binary to a plaintext string that holds the unparsed XML content :)
let xml-as-string := util:base64-decode(post-data//xml-base64)
let parsed-xml := util:parse(xml-as-string)
return
{$xml-as-string}
{$parsed-xml}
Sample Form
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
Upload XML
xmlns=''>
xsi:type="xs:base64Binary"/>
id='post-to-echo'
action='echo-base64-binary.xq' replace="all"
method='post'/>
ref="xml-base64">
Upload XML File:
ref="xml-base64">
XML file encoded in base64binary:
submission="post-to-echo">
Post to Echo
Sample File
This is a small XML file.
Warnings
The attribute data type assignment xsi:type="xs:anyURI" must be associated with the variable used to store the file path name.
References
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.
I dessa publikationerXForms
Licens: CC BY-SA 4.0 · Bearbetat efter en.wikibooks.org
1
0
0
0

Kommentarer






