W3C home > Mailing lists > Public > www-forms@w3.org > January 2007

RE: replace an instance uploading an xml file

From: Klotz, Leigh <Leigh.Klotz@xerox.com>
Date: Wed, 10 Jan 2007 14:37:20 -0800
Message-ID: <E254B0A7E0268949ABFE5EA97B7D0CF402A5A514@usa7061ms01.na.xerox.net>
To: Iņaki Salinas Bueno <inksalinas@gmail.com>, "www-forms" <www-forms@w3.org>
The XForms upload control, like the other XForms controls, provides text content (xsd simple content) for elements or attributes.
The only form control that can change on whole nodesets (xsd complex content) is select with copy, which can swap in nodes on user action.
If you want to allow the user to pick a local file of XML (complex content) and populate an instance with it, you can use upload, but you'll need a server-side operation to take the uploaded text, extract it from the POSTed XML and decode its representation (base64 or hexbinary, or perhaps extract it from the MIME parts if you use multipart-related post) and return it back to the browser with the application/xml mime type. 
It would be something like this:
<xf:instance id="data"> 
  <data xmlns="">
    <name />
<xf:instance id="file">
  <data xmlns="">
   <contents />
<bind nodeset="instance('file')/contents" type="xsd:base64Binary" />
<xf:submission id="upload-my-file" action="uploadAndReturn.cgi" ref="instance('file')/contents" replace="instance" instance="data" />
<xf:input ref="name"><xf:label>Name</xf:label></xf:input>
<xf:upload ref="instance('file')/contents">
 <xf:send ev:event="xforms-value-changed" submission="upload-my-file" />
Then the uploadAndReturn CGI script would accept the base64 encoded contents inside the posted file instance and echo it back, decoded, with MIME type application/xml.
You might think that doing this in JavaScript would be easier and keep the action all on the client, but most user agents prevent scripted access to local file data.


From: www-forms-request@w3.org [mailto:www-forms-request@w3.org] On Behalf Of Iņaki Salinas Bueno
Sent: Wednesday, January 10, 2007 12:07 PM
To: www-forms
Subject: replace an instance uploading an xml file


I'm trying to use the upload control to select an xml file that must replace an instance.

The initial instance data is loaded from "inital.xml". I want to give the user the option to load his own personal data instead of filling the form. I suppose that xforms is prepared for this, but how? 

If I try this:

<xforms:upload ref="instance('the_instance')">
     <xforms:label>File to upload</xforms:label>

Mozilla says:
Error: XForms Error (40): upload element not bound to valid datatype.  Must be bound to one of these datatypes or a type derived from one of these datatypes: xsd:anyURI xsd:base64Binary xsd:hexBinary.

If I try this: 
<xforms:upload bind="the_intance">
     <xforms:label>File to upload</xforms:label>

Mozilla says:
Error: XForms Error (8): id (the_instance) does not refer to a bind element 
Received on Wednesday, 10 January 2007 22:37:47 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:36:19 UTC