Discussion:
Fill instance from local XML file with Blob URL
Till Königshofen
2014-08-09 10:17:33 UTC
Permalink
Hello,

I was looking for a way to load XML files from the local file system
into an XForms instance without sending them to a server first.

I defined a function which retrieves a Blob URL
(http://www.w3.org/TR/FileAPI/#url) from a file selected with a normal
<input id="upload" type="file"/> element:

<script>
getBlobURL = function() {
return URL.createObjectURL(document.getElementById('upload').files[0]);
}
</script>

The submission element is defined as follows:

<xf:submission id="load" replace="instance" instance="data" method="get"
serialization="none">
<xf:resource value="javascript:getBlobURL()"/>
</xf:submission>

To get this to work, I changed line 194 in xsltforms.js (build 604) to

if (uri.match(/^[a-zA-Z0-9+\.\-]+:\/\//) || uri.match(/^blob:/)) {

because otherwise the Blob URL gets "prefixed" with the current URL
loaded in the browser.

The complete example is attached.

Regards
Till
a***@public.gmane.org
2014-08-20 20:06:40 UTC
Permalink
Hello,

Thank you for your contribution and I will update xsltforms.js accordingly.

I wonder if using a get submission with just "file://" would not do the same
with old browsers not supporting Blob. Did you try this before?

Regards,

--Alain

> Le 9 août 2014 à 12:17, Till Königshofen <***@rwth-aachen.de> a
> écrit :
>
>
> Hello,
>
> I was looking for a way to load XML files from the local file system
> into an XForms instance without sending them to a server first.
>
> I defined a function which retrieves a Blob URL
> (http://www.w3.org/TR/FileAPI/#url) from a file selected with a normal
> <input id="upload" type="file"/> element:
>
> <script>
> getBlobURL = function() {
> return URL.createObjectURL(document.getElementById('upload').files[0]);
> }
> </script>
>
> The submission element is defined as follows:
>
> <xf:submission id="load" replace="instance" instance="data" method="get"
> serialization="none">
> <xf:resource value="javascript:getBlobURL()"/>
> </xf:submission>
>
> To get this to work, I changed line 194 in xsltforms.js (build 604) to
>
> if (uri.match(/^[a-zA-Z0-9+\.\-]+:\/\//) || uri.match(/^blob:/)) {
>
> because otherwise the Blob URL gets "prefixed" with the current URL
> loaded in the browser.
>
> The complete example is attached.
>
> Regards
> Till
> ------------------------------------------------------------------------------
> _______________________________________________
> Xsltforms-support mailing list
> Xsltforms-support-5NWGOfrQmneRv+***@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/xsltforms-support
Königshofen, Till
2014-08-21 07:16:01 UTC
Permalink
Hello Alain,

thank you for your response.

I tried using "file://" before and it worked. But in this case the form had to work in an environment where the Java-Plugin is not available.

Kind regards
Till
________________________________
Von: alain.couthures-g9Gpw7ZaukQS+***@public.gmane.org [alain.couthures-g9Gpw7ZaukQS+***@public.gmane.org]
Gesendet: Mittwoch, 20. August 2014 22:06
An: Königshofen, Till; xsltforms-support-5NWGOfrQmneRv+***@public.gmane.org
Betreff: Re: [Xsltforms-support] Fill instance from local XML file with Blob URL

Hello,

Thank you for your contribution and I will update xsltforms.js accordingly.

I wonder if using a get submission with just "file://" would not do the same with old browsers not supporting Blob. Did you try this before?

Regards,

--Alain

> Le 9 août 2014 à 12:17, Till Königshofen <***@rwth-aachen.de> a écrit :
>
>
> Hello,
>
> I was looking for a way to load XML files from the local file system
> into an XForms instance without sending them to a server first.
>
> I defined a function which retrieves a Blob URL
> (http://www.w3.org/TR/FileAPI/#url) from a file selected with a normal
> <input id="upload" type="file"/> element:
>
> <script>
> getBlobURL = function() {
> return URL.createObjectURL(document.getElementById('upload').files[0]);
> }
> </script>
>
> The submission element is defined as follows:
>
> <xf:submission id="load" replace="instance" instance="data" method="get"
> serialization="none">
> <xf:resource value="javascript:getBlobURL()"/>
> </xf:submission>
>
> To get this to work, I changed line 194 in xsltforms.js (build 604) to
>
> if (uri.match(/^[a-zA-Z0-9+\.\-]+:\/\//) || uri.match(/^blob:/)) {
>
> because otherwise the Blob URL gets "prefixed" with the current URL
> loaded in the browser.
>
> The complete example is attached.
>
> Regards
> Till
> ------------------------------------------------------------------------------
> _______________________________________________
> Xsltforms-support mailing list
> Xsltforms-support-5NWGOfrQmneRv+***@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/xsltforms-support
Loading...