/** Replaces the oldChild with the newChild. */
public final Node replaceChild(Node newChild, Node _oldChild) throws DOMException {
if (!(_oldChild instanceof CoreChildNode)) {
throw newDOMException(DOMException.NOT_FOUND_ERR);
}
CoreChildNode oldChild = (CoreChildNode)_oldChild;
if (oldChild.coreGetParent() != this) {
throw newDOMException(DOMException.NOT_FOUND_ERR);
}
checkNewChild(newChild, _oldChild);
CoreChildNode nextSibling = oldChild.coreGetNextSibling();
oldChild.coreDetach(coreGetOwnerDocument(true));
if (newChild instanceof CoreChildNode) {
if (nextSibling == null) {
coreAppendChild((CoreChildNode)newChild, false);
} else {
nextSibling.coreInsertSiblingBefore((CoreChildNode)newChild);
}
} else if (newChild instanceof CoreDocumentFragment) {
if (nextSibling == null) {
coreAppendChildren((CoreDocumentFragment)newChild);
} else {
nextSibling.coreInsertSiblingsBefore((CoreDocumentFragment)newChild);
}
} else {
throw newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
}
return _oldChild;