return newChild;
return oldChild;
    public Node replaceChild(Node newChild, Node oldChild)            throws DOMException {        if (!(oldChild instanceof NodeImpl))            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "wrong node type");        NodeImpl old = (NodeImpl) oldChild;        if (old.getParentGID() != gid)            throw new DOMException(DOMException.NOT_FOUND_ERR,                    "node is not a child of this element");        final DocumentImpl prevDoc = new DocumentImpl(ownerDocument);        NodeImpl previous = (NodeImpl) old.getPreviousSibling();        if (previous == null)            previous = this;        else            previous = getLastNode(previous);        removeAll(old, old.getPath());        ownerDocument.broker.endRemove();        appendChild(old.gid, previous, getPath(), newChild, true);        // reindex if required        ownerDocument.broker.reindex(prevDoc, ownerDocument, null);        try {            ownerDocument.broker.saveCollection(ownerDocument.getCollection());        }        catch (PermissionDeniedException e) {            throw new DOMException(DOMException.INVALID_ACCESS_ERR, e.getMessage());        }        return newChild;    }