Patricia Shanahan wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Patricia Shanahan wrote:
>>> […] Suppose a JS+HTML application were to exist that had tabular data in
>>> JavaScript data structures, and needed to transfer it to a spreadsheet
>>> on a workstation without using any special server set-up. What would be
>>> the best ways to do it?
>>
>> That depends.
>>
>> [Possibilities: DOM Storage, cloud storage]
>
> I am certainly going to need storage for offline operation. In some
> cases, the data collection will happen offline, but the transfer of the
> data to the workstation will be done in a WiFi Internet environment.
>
> DOM storage seemed to me to be far more practical for a data table than
> cookies.
The curious thing is that, contrary to my expectations, DOM Storage [1]
(about to be standardized as Web Storage [2]) also only allows you to store
string values. That is, the main advantage of Web storage over cookies is
that you can store more information there than in cookies (> 4 KiB).
If you want to store/retrieved structured data to/from Web Storage, you
still have to serialize/unserialize it. Which is a bit disappointing. One
would have expected the following to be possible in 21st century browser
scripting:
window.localStorage.setItem("foo", {bar: 42});
/* Object */
var item = window.localStorage.getItem("foo");
/* Number */
var bar = item.bar;
But you have to do:
window.localStorage.setItem("foo_bar", "42");
/* Number */
var bar = +window.localStorage.getItem("foo_bar");
or
window.localStorage.setItem("foo", JSON.stringify({bar: 42});
/* Object */
var item = JSON.parse(window.localStorage.getItem("foo"));
/* Number */
var bar = item.bar;
So you are probably about to write your own wrapper for Web Storage [3].
> I want to minimize the risk of data loss in case of e.g. the browser
> being closed, so I plan to write data to DOM storage as I go along,
> rather than waiting to the end of the observing session.
Good idea. Events [4, 5] will come in handy there.
> I'm planning to use JSON to turn individual observation records
> into strings for storage.
So you have noticed :)
> I'm currently planning to use the string version of an integer sequence
> number, concatenated with a session identifier, as the storage key.
A session identifier does not appear to me to be of much use here, for you
would want to retrieve the data regardless of the session you are in (or are
you considering an application for several users on the same device? In that
case the session identifier should be the user ID). ISTM to be more
important that you use a proper prefix so that data from your application
separates itself from that of other applications.
>> But a Thick Client Web application (in an HTML document in a Web browser)
>> is capable of displaying those spreadsheets and charts by itself, so
>> transferring the data might not be necessary in the first place.
>
> The data from one device may have to be combined with data collected on
> other devices, and will be analyzed and reorganized, before ending up
> summarized in graphs and tables in a scientific paper.
>
> I've seen my lead user's office. He has an iPad, but he also has a
> Windows workstation, and when he wanted to email me some of the result
> files for a project, he used the workstation.
Fair enough.
>>> The simplest and most general solution I have thought of is to display
>>> the data as CSV text, so that the user can select and copy it to the
>>> clipboard. From there, they can do all sorts of things with it, subject
>>> only to device limitations, including pasting it into the body of an
>>> e-mail, or, pasting it into a text editor window and saving it, as a
>>> .csv file, on a thumb drive.
>> That is another option. You can also generate and process JSON or XML,
>> with the additional advantage of transferring more structured
>> information.
>
> It does have to be a format that spreadsheet programs, especially Excel,
> can read. XML is a possibility - I've used it several times in other
> projects -
Yes, given that OpenDocument Spreadsheet (.ods, .fods) and Office Open XML
Spreadsheet (.xlsx) are XML-based, XML might be your best option with regard
to compatibility. However, it also has the greatest overhead of all formats
mentioned so far.
> but can Excel read JSON?
I think that native support is very unlikely. See <
http://json.org/> for
more.
> CSV seems to be the most familiar to the end users.
I was thinking more along the lines of having the same application
processing the code on the workstation that was generated by it on the
mobile device here.
PointedEars
___________
[1] <
https://developer.mozilla.org/en-US/docs/DOM/Storage>
[2] <
http://www.w3.org/TR/webstorage/>
[3] <
http://stackoverflow.com/questions/2010892/storing-objects-in-html5-
localstorage>
[4] <
http://www.w3.org/TR/html5/webappapis.html#events>
[5] <
https://developer.mozilla.org/en-US/docs/HTML/HTML5>
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann