Name

datapointer (LzDatapointer) — A cursor in a dataset.

Synopsis

LZX: datapointer
JavaScript: LzDatapointer
Type: Class
Access: public
Topic: LFC.Data
Declared in: WEB-INF/lps/lfc/data/LzDatapointer.lzs

Description

A datapointer is an object that represents a pointer to a node in a LzDataset. The datapointer can be repositioned using either cursor movements calls such as selectNext(), or by running an XPath request via setXPath().

Datapointers support a subset of the XPath specification, which uses a notation similar to the UNIX file-system to refer to nodes within a dataset. Once a datapointer is bound to a node in a dataset it will keep pointing to that node until it is moved. If the dataset is edited, the behavior of the datapointer will be controlled by its rerunxpath attribute. If this attribute is true, it will continue pointing to its current node as long as it is valid.

The example below demonstrates the use of some of the features of datapaths to retrieve data from a dataset.

Example 7. Using a datapointer to retrieve data from a dataset

 
<canvas height="80">
   <simplelayout spacing="5"/>
   <dataset name="mydata">
     <record> This is some text 
       <deeper>
         <deeprecord> This is a deeper level </deeprecord>
         <deeprecord> It's dark down here! </deeprecord>
         <deeprecord> Last deep record </deeprecord>
       </deeper>
     </record>
     <record> This is more text </record>
     <record> Exciting no? </record>
     <record> The final line of text </record>
   </dataset>
 
   <view>
     <simplelayout/>
     
     <button> Move forward with select
       <handler name="onclick">
         if (mydp.selectNext()) var s = 
         else var s = "hit last record; reset with xpath";
         output.setText(s);
       </handler>
     </button>
     <button> Set with XPath
       <handler name="onclick">
           if (mydp.getNodeName() == "record")
             var xp = 
           else var xp = 
            output.setText();
       </handler>
     </button>
   </view>
 
   <text name="output" width="200">Data will appear here.</text>
 </canvas>

Superclass Chain

node (LzNode) » datapointer (LzDatapointer)

Known Subclasses

Known Direct Subclasses: datapath (LzDatapath)

Details

Properties (6)

context
<attribute name="context" />
public var context = null;
data
<attribute name="data" />
public var data = null;
p
<attribute name="p" type="lzDataNode" />
public var p : LzDataNode = null;
The LzDataNode that the datapointer is pointing to. Calling setAttribute on attribute calls LzDatapointer.setPointer.
pathSymbols
<attribute name="pathSymbols" value="{ ... }" />
public var pathSymbols = { ... };
ppcache
<attribute name="ppcache" value="{ ... }" />
public var ppcache = { ... };
rerunxpath
<attribute name="rerunxpath" type="boolean" />
public var rerunxpath : Boolean = false;
This determines the behavior of the datapointer in response to notification that the dataset the datapointer is mapped to has changed. If rerunxpath is true, the datapointer will always rerun its remembered XPath (set with the xpath property). If it is false, the datapointer will only verify that the node it is pointing to is still in the dataset. If it isn't, the datapointer will rerun its remembered xpath (if it has one) or will print a debug message if any further attempt is made to use its current node as the basis for a relative XPath query.

Setters (4)

Setters for virtual properties, to be used with setAttribute. A setter may or may not have a corresponding getter method; consult the Methods list in this section.

context
p
rerunxpath
xpath

Methods (28)

addNode()
<method name="addNode" args="name, text, attrs" />
public function addNode(name : String, text : String, attrs : Dictionary) : LzDataElement;
Adds a new child node below the current context
addNodeFromPointer()
<method name="addNodeFromPointer" args="dp" />
public function addNodeFromPointer(dp : LzDatapointer) : LzDatapointer;
Duplicates the node that dp is pointing to, and appends it it to the node pointed to by this datapointer, making the added node the last on the list.
comparePointer()
<method name="comparePointer" args="ptr" />
public function comparePointer(ptr : LzDatapointer) : Boolean;
Determines whether this pointer is pointing to the same node as ptr.
deleteNode()
<method name="deleteNode" />
public function deleteNode();
Removes the node pointed to by the datapointer. If rerunxpath is true and xpath has been set, it will be re-evaluated. Otherwise, if the deleted node has a following sibling, the pointer is repositioned at that sibling. Otherwise the pointer is set to null.
deleteNodeAttribute()
<method name="deleteNodeAttribute" args="name" />
public function deleteNodeAttribute(name : String);
Removes the name attribute from the current node.
dupePointer()
<method name="dupePointer" />
public function dupePointer() : LzDataPointer;
Return a new datapointer that points to the same node, has a nullxpath and a falsererunxpath attribute.
getDataset()
<method name="getDataset" />
public function getDataset() : LzDataset;
Returns a reference to the datapointer's dataset.
getNodeAttribute()
<method name="getNodeAttribute" args="name" />
public function getNodeAttribute(name : String) : String;
Returns the value of the current node's name attribute.
getNodeAttributes()
<method name="getNodeAttributes" />
public function getNodeAttributes() : Object;
Returns the attributes of the node pointed to by the datapointer in an Object whose keys are the attribute names and whose values are the attribute values
getNodeCount()
<method name="getNodeCount" />
public function getNodeCount() : Integer;
Counts the number of element nodes that are children of the node that the datapointer is pointing to.
getNodeName()
<method name="getNodeName" />
public function getNodeName() : String;
Gets the name of the node that the datapointer is pointing to.
getNodeOffset()
<method name="getNodeOffset" />
public function getNodeOffset() : Number;
Returns the number of the node that the datapointer is pointing to. Note that XPath indices are 1-based.
getNodeText()
<method name="getNodeText" />
public function getNodeText() : String;
Returns a string that represents a concatenation of the text nodes beneath the current element. getNodeText and getOtherNodeText are the only way to access non-element data nodes.
getOtherNodeText()
<method name="getOtherNodeText" args="n" />
public function getOtherNodeText(n : LzDataNode) : String;
Returns a string that represents a concatenation of the text nodes beneath the node n. This is currently the only way to access non-element data nodes.
getXPath()
<method name="getXPath" args="p" />
public function getXPath(p : Object);
Returns the result of an XPath query without changing the pointer. The result can be:
  • a string -- the result of an operator such as name or attribute
  • a single datapointer -- if the query resolves to a single node
  • an array of datapointers -- if the query resolves to multiple nodes
isValid()
<method name="isValid" />
public function isValid() : Boolean;
Tests whether or not this datapointer is pointing to a valid node.
selectChild()
<method name="selectChild" args="amnt" />
public function selectChild(amnt : Number) : Boolean;
Moves down the data hierarchy to the next child node in the dataset if possible.
selectNext()
<method name="selectNext" args="amnt" />
public function selectNext(amnt : Number) : Boolean;
Selects the next sibling node in the dataset if possible.
selectParent()
<method name="selectParent" args="amnt" />
public function selectParent(amnt : Number) : Boolean;
Moves up the data hierarchy to the next parent node in the dataset if possible.
selectPrev()
<method name="selectPrev" args="amnt" />
public function selectPrev(amnt : Number) : Boolean;
Selects the previous sibling node in the dataset if possible.
serialize()
<method name="serialize" />
public function serialize() : String;
Serialize the current element and its children to an XML string. Note that even if this datapointer's XPath ends in a terminal selector (such as @attribute or text()) this method will return the serialized text of the element that the datapointer points to.
setFromPointer()
<method name="setFromPointer" args="dp" />
public function setFromPointer(dp : LzDataPointer);
Sets this datapointer to the location of the given datapointer
setNodeAttribute()
<method name="setNodeAttribute" args="name, val" />
public function setNodeAttribute(name : String, val : String);
Set the name attribute of the current node to the val.
setNodeName()
<method name="setNodeName" args="name" />
public function setNodeName(name : String);
Sets the name of the current element to the name.
setNodeText()
<method name="setNodeText" args="val" />
public function setNodeText(val : String);
Sets the current node's text to value. When this node is serialized, the text will be represented as the first child node of this node. If the node already has one or more text children, the value of the first text node is set to the val.
setPointer()
<method name="setPointer" args="p" />
public function setPointer(p : LzDataNode);
Points this datapointer at p.
setXPath()
<method name="setXPath" args="p" />
public function setXPath(p : String);
Sets the xpath attribute to param, and sets the current node to the node that it refers to. If the XPath contains a terminal selector such as text(), the datapointer's data property is set to that value. It is error to set a datapointer to an XPath that matches multiple nodes.
xpathQuery()
<method name="xpathQuery" args="p" />
public function xpathQuery(p : Object) : any;
Returns the result of an XPath query without changing the pointer.

Events (6)

ondata
<attribute name="ondata" />
public event ondata;
Sent when the data selected by this datapointer's xpath changes. For XPaths which select a datanode, this means that the datapointer is pointing to a new node. For XPaths which select text data, this means that the datapointer is pointing to a new node, or that the text selected by the xpath has changed. Note that a datapointer mapped to a data node will not receive ondata when the node, say, changes one of its attributes.
onDocumentChange
<attribute name="onDocumentChange" />
public event onDocumentChange;
onerror
<attribute name="onerror" />
public event onerror;
Sent when the dataset that the datapointer is pointing to generates an error.
onp
<attribute name="onp" />
public event onp;
onrerunxpath
<attribute name="onrerunxpath" />
public event onrerunxpath;
ontimeout
<attribute name="ontimeout" />
public event ontimeout;
Sent when a request by the dataset that the datapointer is pointing to times out.

Prototype Properties (1)

defaultattrs
<attribute name="defaultattrs" value="{ ... }" />
public var defaultattrs = { ... };

LZX Synopsis

<class name="LzDatapointer" extends=" LzNode ">
  <attribute name=" context " />
  <attribute name=" data " />
  <attribute name=" p " type="lzDataNode" />
  <attribute name=" pathSymbols " value="{ ... }" />
  <attribute name=" ppcache " value="{ ... }" />
  <attribute name=" rerunxpath " type="boolean" />
  <method name=" addNode " args="name, text, attrs" />
  <method name=" addNodeFromPointer " args="dp" />
  <method name=" comparePointer " args="ptr" />
  <method name=" deleteNode " />
  <method name=" deleteNodeAttribute " args="name" />
  <method name=" dupePointer " />
  <method name=" getDataset " />
  <method name=" getNodeAttribute " args="name" />
  <method name=" getNodeAttributes " />
  <method name=" getNodeCount " />
  <method name=" getNodeName " />
  <method name=" getNodeOffset " />
  <method name=" getNodeText " />
  <method name=" getOtherNodeText " args="n" />
  <method name=" getXPath " args="p" />
  <method name=" isValid " />
  <event name=" ondata " />
  <event name=" onDocumentChange " />
  <event name=" onerror " />
  <event name=" onp " />
  <event name=" onrerunxpath " />
  <event name=" ontimeout " />
  <method name=" selectChild " args="amnt" />
  <method name=" selectNext " args="amnt" />
  <method name=" selectParent " args="amnt" />
  <method name=" selectPrev " args="amnt" />
  <method name=" serialize " />
  <method name=" setFromPointer " args="dp" />
  <method name=" setNodeAttribute " args="name, val" />
  <method name=" setNodeName " args="name" />
  <method name=" setNodeText " args="val" />
  <method name=" setPointer " args="p" />
  <method name=" setXPath " args="p" />
  <method name=" xpathQuery " args="p" />
</class>

JavaScript Synopsis

public LzDatapointer extends  LzNode  {
  public var context  = null;
  public var data  = null;
  public var p  : LzDataNode = null;
  public var pathSymbols  = { ... };
  public var ppcache  = { ... };
  public var rerunxpath  : Boolean = false;
  prototype public function addNode (name : String, text : String, attrs : Dictionary) : LzDataElement;
  prototype public function addNodeFromPointer (dp : LzDatapointer) : LzDatapointer;
  prototype public function comparePointer (ptr : LzDatapointer) : Boolean;
  prototype public var defaultattrs  = { ... };
  prototype public function deleteNode ();
  prototype public function deleteNodeAttribute (name : String);
  prototype public function dupePointer () : LzDataPointer;
  prototype public function getDataset () : LzDataset;
  prototype public function getNodeAttribute (name : String) : String;
  prototype public function getNodeAttributes () : Object;
  prototype public function getNodeCount () : Integer;
  prototype public function getNodeName () : String;
  prototype public function getNodeOffset () : Number;
  prototype public function getNodeText () : String;
  prototype public function getOtherNodeText (n : LzDataNode) : String;
  prototype public function getXPath (p : Object);
  prototype public function isValid () : Boolean;
  prototype public event ondata ;
  prototype public event onDocumentChange ;
  prototype public event onerror ;
  prototype public event onp ;
  prototype public event onrerunxpath ;
  prototype public event ontimeout ;
  prototype public function selectChild (amnt : Number) : Boolean;
  prototype public function selectNext (amnt : Number) : Boolean;
  prototype public function selectParent (amnt : Number) : Boolean;
  prototype public function selectPrev (amnt : Number) : Boolean;
  prototype public function serialize () : String;
  prototype public function setFromPointer (dp : LzDataPointer);
  prototype public function setNodeAttribute (name : String, val : String);
  prototype public function setNodeName (name : String);
  prototype public function setNodeText (val : String);
  prototype public function setPointer (p : LzDataNode);
  prototype public function setXPath (p : String);
  prototype public function xpathQuery (p : Object) : any;
}