Re: [Xsltforms-support] obtaining XML from the user - possible? impossible?
Brought to you by:
alain-couthures
From: C. M. Sperberg-M. <cm...@bl...> - 2012-07-07 23:26:47
|
On Jul 7, 2012, at 1:19 PM, Alain Couthures wrote: >> >> >> Is there any convenient way to get an XML document that >> initially resides on the user's hard disk into an XForms >> instance, so the form can look at it and customize itself >> accordingly? Or is that impossible? > Yes, you can use a submission at "file://" for reading and writing local > files. For security reasons, you will always get a File dialog This sounds excellent, but I'm having a little trouble understanding how it works in detail. Are there any examples readily available? (Is this in rev. 549?) Having written that, I paused and told myself I should try to work it out for myself. When I write two submissions of the form <xforms:submission id="read" method="get" resource="file:///Users/cmsmcq/2012/misc/test.xml" replace="instance" instance="file"/> > and <xforms:submission id="save" method="put" resource="file:///Users/cmsmcq/2012/misc/puttest.xml"/> and provide Read and Save buttons of the form <xforms:submit submission="read"> <xforms:label>Read</xforms:label> </xforms:submit> <xforms:submit submission="save"> <xforms:label>Save</xforms:label> </xforms:submit> then should I get a File dialog for reading or saving, when I click those buttons? I don't; the Loading ... message flashes very quickly, and the trace log gets two lines saying 0 -> Dispatching event xforms-submit on <SPAN class="xforms-submission" id="read"/> 1 -> Dispatching event xforms-submit-error on <SPAN class="xforms-submission" id="read"/> The document text.xml is not loaded into the 'file' instance. So I'm clearly doing something wrong here; I'll continue to play with this, but if any reader of this list can see where I'm going wrong, I'll be grateful for a hint. > (I could > allow a direct access to local files when no distant HTTP server is > used, what do you think?). "How can I use XForms on a local system without having to set up an HTTP server or install eXist or something?" is definitely a question I get often. So yes, if you have found a way to make it work, I think it could be useful for many people who are first starting with XForms. >> ... >> If xf:upload were able to populate an instance (or an element >> in an instance) with an uploaded document, that would (I >> think) do what I think I need. But if I read the 1.1 spec correctly, >> xf:upload data cannot be parsed XML data, only base64Binary >> and so on. > Yes, xf:upload is just for content. One workaround I have found seems to work for loading user-supplied XML documents into the instance. I record it here in case anyone else finds it handy and hasn't already thought of it: I upload the base64 data to a script on the server which performs a base64 decoding and sends the file back to the client as text/xml. The submission specifies replace="instance", so the XML document specified by the user is loaded into a specified XForms instance, where the form can work with it. A simple example is at http://blackmesatech.com/2012/06/testcase/upload-into-instance.xhtml (The example works in Firefox, Chrome, and Opera. For reasons I have not yet uncovered, xf:upload does not seem to work for me in Safari 5.1.7 at all. The trace shows events xforms-submit, xforms-submit-serialize, and xforms-submit-error, but I have not yet figured out what is going wrong.) -- **************************************************************** * C. M. Sperberg-McQueen, Black Mesa Technologies LLC * http://www.blackmesatech.com * http://cmsmcq.com/mib * http://balisage.net **************************************************************** |