Skip to content

Commit f694ffe

Browse files
committed
Merge branch '3.4' into 4.2
* 3.4: Clarify using chained filterXPath
2 parents 1bb7072 + 585683c commit f694ffe

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

components/dom_crawler.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ Call an anonymous function on each node of the list::
229229
The anonymous function receives the node (as a Crawler) and the position as arguments.
230230
The result is an array of values returned by the anonymous function calls.
231231

232+
When using nested crawler, beware that ``filterXPath()`` is evaluated in the
233+
context of the crawler::
234+
235+
$crawler->filterXPath('parent')->each(function (Crawler $parentCrawler, $i) {
236+
// DON'T DO THIS: direct child can not be found
237+
$subCrawler = $parentCrawler->filterXPath('sub-tag/sub-child-tag');
238+
239+
// DO THIS: specify the parent tag too
240+
$subCrawler = $parentCrawler->filterXPath('parent/sub-tag/sub-child-tag');
241+
$subCrawler = $parentCrawler->filterXPath('node()/sub-tag/sub-child-tag');
242+
});
243+
232244
Adding the Content
233245
~~~~~~~~~~~~~~~~~~
234246

0 commit comments

Comments
 (0)