You are here

public function QueryPath::unwrap in QueryPath 6

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

File

QueryPath/QueryPath.php, line 734

Class

QueryPath

Code

public function unwrap() {
  $parents = new SplObjectStorage();
  foreach ($this->matches as $m) {
    if ($m
      ->isSameNode($m->ownerDocument->documentElement)) {
      throw new QueryPathException('Cannot unwrap the root element.');
    }
    $parent = $m->parentNode;
    $old = $parent
      ->removeChild($m);
    $parent->parentNode
      ->insertBefore($old, $parent);
    $parents
      ->attach($parent);
  }
  foreach ($parents as $ele) {
    $ele->parentNode
      ->removeChild($ele);
  }
  return $this;
}