RE: replace an instance uploading an xml file

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 />
  </data>
</xf:instance>
<xf:instance id="file">
  <data xmlns="">
   <contents />
  </data>
</xf:instance>
<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:label>File</xf:label>
 <xf:send ev:event="xforms-value-changed" submission="upload-my-file" />
</xf:upload>
 
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.
 
Leigh.
 

________________________________

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


Hello,

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>
</xforms:upload>

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>
</xforms:upload>

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