9.6.2. Accessing node neighbors

There is a few methods provided by every FSNode reference that can be used to access other nodes in the tree. Each of the methods returns either a FSNode reference pointing to the requested node, or zero if the requested node does not exist. For example, the following code may be used to make the active node's parent node active:

$this = $this->parent if ($this->parent);

The above code states: activate the parent node of the currently active node in case the currently active node has a parent.

The following table describes all available FSNode methods:

Table 2. FSNode methods

Method nameDescription
parentReturn node's parent node.
firstsonReturn the first child node of the given node (the first node depending on the given node).
rbrother Return the right brother of the given node. However, hence the nodes may be displayed in the order given by the special FS-format numbering attribute @N, the returned node need not necessarily be displayed to the right of the given node. This is because the ordering according to the special numbering attribute does not have to correspond to the natural structure ordering of the tree.
lbrother Return the left brother of the given node. However, as for the right brother, hence the nodes may be displayed in the order given by the special FS-format numbering attribute @N, the returned node need not necessarily be displayed to the left of the given node. This is because the ordering according to the special numbering attribute does not have to correspond to the natural structure ordering of the tree.
following(top?) Return the next node of the given node in the natural ordering of the tree provided by the tree structure. E.g. if the given node has a child, this child is returned. If the node has no childs but does have a right brother, FSNode reference to the right brother is returned. If no child and no right brother exists for the given node, the method looks for a right brother of its nearest ancestor, etc. Starting from the root of the tree and calling this method repeatedly on the returned nodes ensures that all the nodes in the trees are accessed during the procedure. If the optional argument top contains a FSNode reference, the searching is limited to the subtree governed by the node of top.
previous(top?) Return the previous node of the given node in the natural ordering of the tree provided by the tree structure (see the above description of the following method for more detail on the ordering). If the optional argument top contains a FSNode reference, the searching is limited to the subtree governed by the node of top.
children Return a list of all child-nodes of the given node. The nodes in the list are ordered in their structural order starting from the first son of their parent, each node followed by its right brother.