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
<?xml version="1.0"?>
<?xml-stylesheet href="build/xsltforms.xsl" type="text/xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml"; xmlns:xf="http://www.w3.org/2002/xforms";>
  <head>
    <meta charset="UTF-8"/>
    <title>XForms Blob Example</title>
    <xf:model>
      <xf:instance id="data">
        <data xmlns=""/>
      </xf:instance>
      <xf:submission id="load" replace="instance" instance="data" method="get" serialization="none">
        <xf:resource value="javascript:getBlobURL()"/>
      </xf:submission>
    </xf:model>
  </head>
  <body>
    <input id="upload" type="file"/>
    <br/>
    <xf:submit submission="load">
      <xf:label>Load</xf:label>
    </xf:submit>
    <br/>
    <xf:output ref="instance('data')">
      <xf:label>Output: </xf:label>
    </xf:output>
    <script>
      getBlobURL = function(){
        return URL.createObjectURL(document.getElementById('upload').files[0]);
      }
    </script>
  </body>
</html>
<?xml version="1.0"?>
<test>Success</test>
------------------------------------------------------------------------------
_______________________________________________
Xsltforms-support mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xsltforms-support

Reply via email to