Unions

When addressing nodes, it is possible to perform a single query that uses multiple expressions. This is referred to as addressing the union of those expressions.

<?php
// Returns the li child nodes of all ul and ol nodes
$list = $xpath->query('//ol/li|//ul/li');

// Returns the th and td nodes of all tr nodes
$list = $xpath->query('//tr/th|//tr/td');
?>
  • The first example returns all list items (li) of both unordered (ul) and ordered (ol)) lists.
  • The second example returns all header (th) and data (td) cells of table rows (tr).

© DOM Extension — Web Scraping

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