You are here

public function QueryPath::xpath in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/QueryPath.php \QueryPath::xpath()
  2. 7.2 QueryPath/QueryPath.php \QueryPath::xpath()

File

QueryPath/QueryPath.php, line 283

Class

QueryPath

Code

public function xpath($query) {
  $xpath = new DOMXPath($this->document);
  $found = new SplObjectStorage();
  foreach ($this->matches as $item) {
    $nl = $xpath
      ->query($query, $item);
    if ($nl->length > 0) {
      for ($i = 0; $i < $nl->length; ++$i) {
        $found
          ->attach($nl
          ->item($i));
      }
    }
  }
  $this
    ->setMatches($found);
  return $this;
}