Till Königshofen
2014-08-09 10:17:33 UTC
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
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