When you work with properties and property lists in PilotScript, you can treat each data record as if it were a simple, flat property list, illustrated as follows: maximum := 1000; However, data records can be more complex. They can be organized into a hierarchical tree of nodes that fall below a single root node owned by the data record:
Each non-root node has a single parent node and each node can have zero, one, or more child nodes. Each node has an associated property list. A property that exists on a property list below the root node is known as a deep property. When using a simple name for a data record property, such as "maximum", you imply that the property is in the default property list for that data record. The default property list is the property list associated with the hierarchy's root node. In many cases, a data record only has the root node and its single property list. You can treat such a record as a flat list of properties and values. You can treat any record in this manner, if you are ignoring any deep property lists elsewhere in the data tree and you only require access to the default property list. To access deep properties in a data record tree, use a special path syntax for locating properties. Deep Property Path NamesWhen working with deep properties, the first thing to understand is how to construct the deep property's name. This name begins with the path to the node containing the property list where the property exists. The node path is followed by a forward slash and then the name of the property itself. Therefore a node path and a deep property path share the same syntax. The only distinction between them, is the context in which they are used. This follows the analogy of a file system object, where a deep property corresponds to a file name, written as the leaf element of a file path. Note that in PilotScript, a hierarchical property name's value is always written using the
isMine := %'/annotations/complex/history/submitter'; %'/annotations/complex/history/submission_date' := '2005/06/30'; Or, identically: property('/annotations/complex/history/submission_date') := '2005/06/30';
To identify a hierarchical property (for example, to find out if it is defined), simply use the hierarchical path name in single quotes, as you would with a non-hierarchical property name. For example: IF %'/annotations/complex/history/amendment_date' IS DEFINED THEN
Remove('/annotations/complex/history/amendment_date');
END IF;
Deep Node Path NamesThere are some PilotScript functions that require the name of a node in a hierarchical data
structure. These functions are A node path name begins with a forward slash followed by the node names that make up the path to the node. The first name is the name of the root node. The final item in the path is the name of the node that is identified by the path. IF (IsValidLocation('/annotations/complex/history') THEN
numhist := NumChildren('/annotations/complex/history');
END IF;
Note:
To easily enter deep properties and node path names, view the data using a
Data Record Tree Viewer component. Click on the property node
to reveal its full path. To copy the path name to the clipboard, press
ENTER and then paste it where needed.
XPath ExtensionsPilotScript uses an XPath engine to decode the hierarchical path names of nodes, in the tree. Therefore you can use more elaborate syntax for the node path, than in the examples shown above. For further details on XPath syntax, consult an appropriate reference (e.g., zvon.org). The examples below illustrate some interesting possibilities. /* The annotation which has a property named "id" with a value of 3 */
%'/annotations/annotation[@id="3"]/submitter' := 'czekanowski';
/* The second annotation child */
%'/annotations/annotation[2]/submitter' := 'czekanowski';
/* A longer-winded way of saying the same thing */
%'/annotations/child::annotation[position()=2]/submitter' := 'czekanowski';
/* Any node in the tree named "annotation" and submitter named "czekanowski" */
date := %'//annotation[@submitter="czekanowski"]/submission_date';
/* Any node in the tree whose name starts with "scitegic." and has
a child named "annotation"*/
issci := IsValidLocation('//*[starts-with(name(),'scitegic.')]/annotation');
/* Any annotation node in the tree with exactly three ancestor nodes */
isanno := IsValidLocation('/*/*/*/annotation');
Ambiguous Path Names and Looping Over NodesWhether using XPath extensions or the simple path syntax for deep nodes and properties, it is possible that an expression has a logical mapping to more than one item. These ambiguous path names only identify the first item found. For example, if a node named "Family" has multiple child nodes named "Species", then the following statement would appear ambiguous: /* Add to a running total the value property from the result node */ @etotal += %'/Family/Species/estimate'; Only the value from first Species node is used, even though there is more than one node that matches the path "/Family/Species". To deal with multiple nodes, you can cycle through the matching nodes, as in the following example: FOR #i in 1 .. NumChildren('/Family')
LOOP
IF Property('/Family/Species['.#i.']/estimate') IS DEFINED THEN
@etotal += Property('/Family/Species['.#i.']/estimate');
END IF;
END LOOP;
| ||||||||||