Personal tools

LiteralDataProposal

From OpenLaszlo

Contents

Introduction


Proposal

An LZX syntax for literal XML data, to enhance the current <dataset> literal data special form. This will also be useful for specifying initial data in a <dataset> while also allowing methods, handlers, and other LZX tag to be contained as well.

Overview

A new tag <data> is introduced which can contain literal XML data. It can be used in any LZX node, and will appear as a named attribute of it's parent node. It will be bound to an LzDataElement representing the data at runtime.

Changes

The LZX tag compiler will need to know that <data> is a new special tag which contains literal data.

For backward compatibility, <dataset> will need an attribute which says to treat its children as standard node content instead of as literal XML data.

Examples


<data name="mydata">
   <flavors>
       <flavor name="vanilla"/>
       <flavor name="chocolate"/>
       <flavor name="pistachio"/>
     </flavors>
</data>
<data name="mydata">
   <flavors>
       <flavor name="vanilla"/>
       <flavor name="chocolate"/>
       <flavor name="pistachio"/>
     </flavors>
</data>


<dataset datafromchild="true" >
  the first anonymous data child will be set as dataset's initialdata 
   <data>
     <foo>bar</foo>
   </data>   
   <handler name="ondata">
        ...
   </handler>
   <method name="myownmethod"> .... </method>
</dataset>

XML data which does not have a single parent node

There is a subtle issue with XML literal data, compare these two examples:

   <dataset name="mydata">
     <flavors>
       <flavor name="vanilla"/>
       <flavor name="chocolate"/>
       <flavor name="pistachio"/>
     </flavors>
   </dataset>
   <dataset name="mydata">
       <flavor name="vanilla"/>
       <flavor name="chocolate"/>
       <flavor name="pistachio"/>
   </dataset>


The second case above is not documented as supported (the docs specify a single root node for dataset data), however it is currently supported by the system. It leads to a dataset who's serialization looks like

  <mydata><flavor name="vanilla"><flavor name="chocolate"/><flavor name="pistachio"/></mydata>


For backward compatibility, both cases could still be supported, or we could throw a warning or error in the second case.

   This is OK, data has a single top level node
  <dataset name="mydata" datafromchild="true">
     <data>
      <flavors>
       <flavor name="vanilla"/>
       <flavor name="chocolate"/>
       <flavor name="pistachio"/>
     </flavors>
   </data>
  </dataset>
 Multiple top level data nodes, should we be back compatible with current dataset behavior?
 <dataset name="mydata">
       <data>
        <flavor name="vanilla"/>
        <flavor name="chocolate"/>
        <flavor name="pistachio"/>
       </data>
   </dataset>

<data> Tag Attributes

The <data> tag should store a chunk of literal XML data, and compile into a reference to an LzDataElement which represents that XML.

The data tag will support at least an optional name attribute, which will bind the value to an attribute of that name in the parent node. This could be useful for general coding which involves manipulating XML chunks, not just inside of a dataset.

<view>
  <data name="mycolors">
       <colors>
         <color>red<color>
         <color>blue</color>
       </colors>
  </data>
</view>



Design Questions


Currently datasets in LZX don't allow both a type of http AND an initial literal data value.

But that seems like it would be useful app developers, to have a placeholder dataset initial value, but then to overwrite that later with a dynamic network request.

Example usage:

<dataset name="icecream" type="local" [defaults to httpdataprovider] src="http:todaysmenu.xml">
   <data>
    <flavors>
      <flavor name="vanilla"/>
      <flavor name="chocolate"/>
      <flavor name="pistachio"/>
    </flavors>
   </data>
</dataset>
<view datapath="icecream:/flavors">
  ..
  <button onclick="icecream.doRequest()">Update</button>
</view>