QueryPath\DOMQuery::unwrap PHP Method

unwrap() public method

This takes the given list of nodes and "unwraps" them, moving them out of their parent node, and then deleting the parent node. For example, consider this:
See also: wrap()
Since: 2.1
Author: mbutcher
public unwrap ( )
    public function unwrap()
    {
        // We do this in two loops in order to
        // capture the case where two matches are
        // under the same parent. Othwerwise we might
        // remove a match before we can move it.
        $parents = new \SplObjectStorage();
        foreach ($this->matches as $m) {
            // Cannot unwrap the root element.
            if ($m->isSameNode($m->ownerDocument->documentElement)) {
                throw new \QueryPath\Exception('Cannot unwrap the root element.');
            }
            // Move children to peer of parent.
            $parent = $m->parentNode;
            $old = $parent->removeChild($m);
            $parent->parentNode->insertBefore($old, $parent);
            $parents->attach($parent);
        }
        // Now that all the children are moved, we
        // remove all of the parents.
        foreach ($parents as $ele) {
            $ele->parentNode->removeChild($ele);
        }
        return $this;
    }