Skip to content

Commit b5a07cf

Browse files
committed
Merge branch '4.2'
* 4.2: Clarify using chained filterXPath
2 parents 5d6766a + f694ffe commit b5a07cf

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
@@ -252,6 +252,18 @@ Call an anonymous function on each node of the list::
252252
The anonymous function receives the node (as a Crawler) and the position as arguments.
253253
The result is an array of values returned by the anonymous function calls.
254254

255+
When using nested crawler, beware that ``filterXPath()`` is evaluated in the
256+
context of the crawler::
257+
258+
$crawler->filterXPath('parent')->each(function (Crawler $parentCrawler, $i) {
259+
// DON'T DO THIS: direct child can not be found
260+
$subCrawler = $parentCrawler->filterXPath('sub-tag/sub-child-tag');
261+
262+
// DO THIS: specify the parent tag too
263+
$subCrawler = $parentCrawler->filterXPath('parent/sub-tag/sub-child-tag');
264+
$subCrawler = $parentCrawler->filterXPath('node()/sub-tag/sub-child-tag');
265+
});
266+
255267
Adding the Content
256268
~~~~~~~~~~~~~~~~~~
257269

0 commit comments

Comments
 (0)