Skip to content

Commit 585683c

Browse files
committed
Minor reword
1 parent 5fdfc58 commit 585683c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

components/dom_crawler.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,6 @@ Node Filtering
7676
Using XPath expressions is really easy::
7777

7878
$crawler = $crawler->filterXPath('descendant-or-self::body/p');
79-
80-
// To chained "filterXPath" : be aware that filterXPath is evaluated in the context of the crawler
81-
$crawler->filterXPath('parent')->each(function (Crawler $parentCrawler, $i) {
82-
// NOK : Direct child can not be found
83-
$childCrawler = $parentCrawler->filterXPath('child-tag/sub-child-tag');
84-
85-
// OK : You must specify parent tag
86-
$subChildCrawler = $parentCrawler->filterXPath('parent/child-tag/sub-child-tag');
87-
$subChildCrawler = $parentCrawler->filterXPath('node()/child-tag/sub-child-tag');
88-
});
89-
9079

9180
.. tip::
9281

@@ -235,6 +224,18 @@ Call an anonymous function on each node of the list::
235224
The anonymous function receives the node (as a Crawler) and the position as arguments.
236225
The result is an array of values returned by the anonymous function calls.
237226

227+
When using nested crawler, beware that ``filterXPath()`` is evaluated in the
228+
context of the crawler::
229+
230+
$crawler->filterXPath('parent')->each(function (Crawler $parentCrawler, $i) {
231+
// DON'T DO THIS: direct child can not be found
232+
$subCrawler = $parentCrawler->filterXPath('sub-tag/sub-child-tag');
233+
234+
// DO THIS: specify the parent tag too
235+
$subCrawler = $parentCrawler->filterXPath('parent/sub-tag/sub-child-tag');
236+
$subCrawler = $parentCrawler->filterXPath('node()/sub-tag/sub-child-tag');
237+
});
238+
238239
Adding the Content
239240
~~~~~~~~~~~~~~~~~~
240241

0 commit comments

Comments
 (0)