0
<ul id="menu">
  <li><a href='#'>First Item</a></li>
  <li><a href='#'>Second Item</a></li>
</ul>

I can access all links via xpath query.

    $result = $crawler->filterXPath('//ul[@id="menu"]/li/a');

but i wonder if is it possible to access parent element of child element using filterXPath() method without editing xpath query in PHP DomCrawler ?

For example i want to access //ul[@id="menu"] using node element in each() method.

$result = $crawler->filterXPath('//ul[@id="menu"]/li/a');
if($result->count() < 1){
  exit('Query not found.');
}
$result->each(function (Crawler $node)){
    $parentOfNode = $node->parent() // ??
    //...
}; 
cyb0k
  • 2,478
  • 23
  • 19
  • Your XPath doesn't correspond to the HTML snippet posted. Maybe you meant `//ul[@id="menu"]/li/a`? – har07 Aug 11 '15 at 13:01
  • How about [`$node->parents()`](http://api.symfony.com/2.7/Symfony/Component/DomCrawler/Crawler.html#method_parents)? – har07 Aug 11 '15 at 13:04
  • $node->parents() gives me parent node list but i want to access get html content of parent element. – cyb0k Aug 11 '15 at 13:06

0 Answers0