Thread: [Xsltforms-support] obtaining XML from the user - possible? impossible?
Brought to you by:
alain-couthures
From: C. M. Sperberg-M. <cm...@bl...> - 2012-07-06 23:03:02
|
A rather general question has come up. A friend has asked for a form that asks the user some questions based on the content of an XML document to be supplied by the user. 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? 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. I'd be happy to provide a text widget and have the user copy the file and paste it in, if there were a way to get the parsed XML structure back out, but that has not worked for me in the past. (On the other hand, I think that that is, more or less, how the TinyMCE widget works, so it might be technically feasible.) Does anyone here have relevant experience or advice? Thanks! Michael -- **************************************************************** * C. M. Sperberg-McQueen, Black Mesa Technologies LLC * http://www.blackmesatech.com * http://cmsmcq.com/mib * http://balisage.net **************************************************************** |
From: Alain C. <ala...@ag...> - 2012-07-07 19:19:49
|
Hello Michael, > A rather general question has come up. A friend has asked > for a form that asks the user some questions based on the content > of an XML document to be supplied by the user. > > 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 (I could allow a direct access to local files when no distant HTTP server is used, what do you think?). I have already designed some basic XML editor with this. > > 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. > > I'd be happy to provide a text widget and have the user copy > the file and paste it in, if there were a way to get the parsed XML > structure back out, but that has not worked for me in the past. > (On the other hand, I think that that is, more or less, how the > TinyMCE widget works, so it might be technically feasible.) A textarea control could be used and a schema type could activated this. It could then be possible to validate the content when it is well-formed. Validating it according to a schema would be more complex for XSLTForms... > > Does anyone here have relevant experience or advice? Another possibility would be to define and use some parse() function (the W3C Work Group has not yet decided what to specify)... The problem is to know if the resulting XML document would be effective as some automatically generated instance or if it would just exist during an action processing. Thank you for your comments and suggestions! -Alain |
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 **************************************************************** |
From: Andre C. <ac...@01...> - 2012-07-08 03:06:07
|
Hi C.M., I am not sure that this can help, but, thanks to Alain, for reading,since you get the file dialog anyway, you would not specify the file on submission, so I use: <xf:submission id="load"method="get"serialization="none"replace="instance"action="file:// <view-source:file:///>"> <xf:message level="modeless"ev:event="xforms-submit-error">Submit error.</xf:message> </xf:submission> And the button is <xf:submit submission="load"> <xf:label>Load</xf:label> </xf:submit> ac > 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.) > > |
From: C. M. Sperberg-M. <cm...@bl...> - 2012-07-08 18:11:22
|
On Jul 7, 2012, at 8:06 PM, Andre Cusson wrote: > Hi C.M., > > I am not sure that this can help, but, thanks to Alain, for reading,since you get the file dialog anyway, you would not specify the file on submission, so I use: > > <xf:submission id="load"method="get"serialization="none"replace="instance"action="file:// <view-source:file:///>"> > <xf:message level="modeless"ev:event="xforms-submit-error">Submit error.</xf:message> > </xf:submission> > > > And the button is > > <xf:submit submission="load"> > <xf:label>Load</xf:label> > </xf:submit> Thank you; concrete examples are almost always helpful. When I try to use this code in a test form, however, I get messages saying "document.applets.xsltforms.readFile is not a function" (Firefox, Opera) or "Object #<HTMLAppletElement> has no method 'readFile'" (Chrome). Perhaps this means I need to do something on my server to ensure that the applet is loaded correctly? Or perhaps not: I get the same messages when I press the Load button in page http://www.hyperbase.com/library/hyperform/stratml/asset/xml/4psc.xml which I assume is correctly configured. Is there anything needed to ensure the applet loads correctly other than (1) making sure xsltforms.jar is in the same directory on the server as xsltforms.xsl and xsltforms.js? and (2) making sure the user has not configured the browser to refuse to load Java applets? -- **************************************************************** * C. M. Sperberg-McQueen, Black Mesa Technologies LLC * http://www.blackmesatech.com * http://cmsmcq.com/mib * http://balisage.net **************************************************************** |
From: C. M. Sperberg-M. <cm...@bl...> - 2012-07-08 19:33:02
|
On Jul 8, 2012, at 12:11 PM, C. M. Sperberg-McQueen wrote: > ... > Is there anything needed to ensure the applet loads correctly > other than (1) making sure xsltforms.jar is in the same directory > on the server as xsltforms.xsl and xsltforms.js? and (2) making > sure the user has not configured the browser to refuse to load > Java applets? Further on this: it turns out that on OS X, it was harder than I expected to satisfy condition (2). The 'Enable java' checkbox in the Safari Preferences dialog did not suffice; I had to install the Java 6 plugin (which I was prompted to do by clicking on the words 'inactive plugin' displayed over the web page). A similar sequence of actions was needed for Chrome, Firefox, and Opera. Once I had installed the Java plugin in each of my browsers, and restarted them both Alain's test case (now on my server at http://blackmesatech.com/2012/07/dh/applet-test.xml) and Andre Cusson's StratML editor (at http://www.hyperbase.com/library/hyperform/stratml/asset/xml/4psc.xml) began to behave as expected. That is, the buttons that connect to file: URIs open a file dialog box. (It was mystifying when it didn't work, partly because -- as others have also reported -- the browsers' error messages are not very helpful in making clear to the user what is going on.) Sorry for the false alarm! -- **************************************************************** * C. M. Sperberg-McQueen, Black Mesa Technologies LLC * http://www.blackmesatech.com * http://cmsmcq.com/mib * http://balisage.net **************************************************************** |