src/SimpleDOM.php
public function replaceSelf(SimpleXMLElement $new)
    {
        $old = dom_import_simplexml($this);
        $new = $old->ownerDocument->importNode(dom_import_simplexml($new), true);

        $node = $old->parentNode->replaceChild($new, $old);
        return simplexml_import_dom($node, get_class($this));
    }
public function replaceSelf(SimpleXMLElement $new)
    {
        $old = dom_import_simplexml($this);
        $new = $old->ownerDocument->importNode(dom_import_simplexml($new), true);

        $node = $old->parentNode->replaceChild($new, $old);
        return simplexml_import_dom($node, get_class($this));
    }
Replace this node

This is a convenience method. The same result can be achieved with
<code>
$node->parentNode()->replaceChild($new, $node);
</code>

@param    SimpleXMLElement $new New node
@return    SimpleDOM                    Replaced node on success