public function deleteNodes($xpath)
    {
        if (!is_string($xpath)) {
            throw new InvalidArgumentException(
                'Argument 1 passed to deleteNodes() must be a string, ' . gettype($xpath) . ' given'
            );
        }

        $nodes = $this->_xpath($xpath);

        if (isset($nodes[0])) {
            $tmp = dom_import_simplexml($nodes[0]);

            if ($tmp->isSameNode($tmp->ownerDocument->documentElement)) {
                unset($nodes[0]);
            }
        }

        foreach ($nodes as $node) {
            $node->deleteSelf();
        }

        return count($nodes);
    }