Relative Addressing

The above examples use what is called absolute addressing, similar in concept to absolute filesystem paths. The next example covers use relative addressing.

<?php
// Returns all ul nodes that have li child nodes
$list = $xpath->query('//body//ul/li/..');
?>

Where //body//ul/li selects li nodes, //body//ul/li/.. instead selects ul nodes by using relative addressing (specifically ..) to indicate that the parent node of the addressed node (li) should be returned rather than the addressed node itself. Compare this with the same sequence used to refer to the parent directory of the current directory on a UNIX filesystem.


© DOM Extension — Web Scraping

>>> Back to TABLE OF CONTENTS <<<
Category: Article | Added by: Marsipan (01.09.2014)
Views: 297 | Rating: 0.0/0
Total comments: 0
avatar