You are here

public function QueryPath::parents in QueryPath 6

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

File

QueryPath/QueryPath.php, line 1119

Class

QueryPath

Code

public function parents($selector = NULL) {
  $found = new SplObjectStorage();
  foreach ($this->matches as $m) {
    while ($m->parentNode->nodeType !== XML_DOCUMENT_NODE) {
      $m = $m->parentNode;
      if ($m->nodeType === XML_ELEMENT_NODE) {
        if (!empty($selector)) {
          if (qp($m, NULL, $this->options)
            ->is($selector) > 0) {
            $found
              ->attach($m);
          }
        }
        else {
          $found
            ->attach($m);
        }
      }
    }
  }
  $this
    ->setMatches($found);
  return $this;
}