`

Data Access, Manipulation, and Binding (openlaszlo)

阅读更多

5. Data Access, Manipulation, and Binding

LZX is designed to make it easy to write data-driven applications in which the values of data sources define the appearance and actions of the program. It does this through tags and APIs that allow you to get access to data over http, manipulate XML data in memory, and, significantly, bind the data hierarchy to the view hierarchy.

The following paragraphs summarize these key features of the LZX data-handling architecture. Chapter 36, Data, XML, and XPath discusses this subject in depth.

 

5.1. Data Access

LZX programs manipulate XML-formatted data, which may be

  • embedded in the program text,

  • read in from a source when the program is compiled, or

  • read in from a source when the program is running.

XML sources are stored as objects called datasets. The <dataset> tag has attributes that allow you to, for example, control caching on the client and server, include or exclude http headers, queue requests, and so forth. Objects created by <dataset> are called lz.datasets. Methods on lz.datasets allow you to, for example, get and set query strings, parameters and so forth.

 

5.2.  Data Manipulation

LZX employs datapointers, which are objects that represent pointers to nodes in datasets, to locate and manipulate content. Datapointers support a subset of XPath, which is a W3C standard specification for identifying paths of an XML document, or in the case of LZX, datasets. XPath uses a notation similar to the UNIX file-system to refer to nodes within a dataset. Datapointers can be repositioned using both procedural calls such as selectNext() and by running an XPath request using setXPath().

Because it incorporates 精密的pattern matching, XPath notation is extremely 简明的and powerful. A single XPath expression can represent an 任意的large number of XML elements. Using methods such as addNode(), setNodeName(), setXpath(), and selectParent(), you can build and manipulate XML structures.

 

5.3. Data Binding

LZX provides a unique way of merging any arbitrarily shaped data hierarchy with any display hierarchy; this capability is called data binding. It is implemented in such a way that the data context of a child in the display hierarchy is implicitly the data context of its parent. Moreover, it is possible to 告知the system to create an arbitrary bit of view hierarchy to represent each element in a set of selected data.

The way this is done is by binding views to datapointers. A datapath is a special case of datapointer that 明确的marries the data hierarchy to the view hierarchy, as in, for example:

<view name="bob" datapath="testdata:/*">

where testdata refers to a dataset defined earlier in the program.

If this sounds a little abstract, well, it is. Therefore we'll keep the discussion short here and defer longer explanations to Chapter 37, Data Access and Binding; you may also want to examine some of the examples on http://www.laszlosystems.com/demos to get a feel for what can be done when applications are truly data-driven.

The key thing to understand is that while other languages and technologies have implemented merge algorithms that may appear similar on the surface, LZX's data binding is novel in the creation of program objects that retain a live connection with the entities of the data source.

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics