DOMIT! v 0.1 Tutorial
<<    index    >>
1    2    3    4    5    6    7    8    9     10    11    12    13    14    15   
16    17    18    19    20    21    22    23    24    25    26   
lastChild and previousSibling

The lastChild and previousSibling properties of a DOM Document are the inverse of firstChild and nextSibling.

lastChild is a reference to the last child node in a sequence of nodes -- in other words, childNodes[count[childNodes] - 1].

previousSibling is a reference to the node immediately prior to the current node -- for instance, the previousSibling of childNodes[2] is childNodes[1].

The following example reverses the loop from the previous example:

if ($cdCollection->documentElement->hasChildNodes()) {
	$currentNode =& $cdCollection->documentElement->lastChild;
	$i = count($cdCollection->documentElement->childNodes) - 1;
	
	while ($currentNode != null) {
		echo ("The id of child node $i is: " . 
			$currentNode->attributes["id"] . 
			"\n");
			
		$currentNode =& $currentNode->previousSibling;
		$i--;		
	}
}


The results are a reverse of the childNodes loop:

The id of child node 2 is: 0003
The id of child node 1 is: 0002
The id of child node 0 is: 0001


Documentation generated by ClassyDoc, using the DOMIT! and SAXY parsers.
Please visit Engage Interactive to download free copies.