@@ -76,17 +76,6 @@ Node Filtering
76
76
Using XPath expressions is really easy::
77
77
78
78
$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
-
90
79
91
80
.. tip ::
92
81
@@ -235,6 +224,18 @@ Call an anonymous function on each node of the list::
235
224
The anonymous function receives the node (as a Crawler) and the position as arguments.
236
225
The result is an array of values returned by the anonymous function calls.
237
226
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
+
238
239
Adding the Content
239
240
~~~~~~~~~~~~~~~~~~
240
241
0 commit comments