Replace the old child with a new child.

@param newChild New child to replace with
@param oldChild Old child to be replaced

@return The new child

@throws DOMException
974798
public Node replaceChild(Node newChild, Node oldChild) throws DOMException
  {

    if (oldChild == null || oldChild.getParentNode() != this)
      return null;

    ElemTemplateElement newChildElem = ((ElemTemplateElement) newChild);
    ElemTemplateElement oldChildElem = ((ElemTemplateElement) oldChild);

    // Fix up previous sibling.
    ElemTemplateElement prev =
      (ElemTemplateElement) oldChildElem.getPreviousSibling();

    if (null != prev)
      prev.m_nextSibling = newChildElem;

    // Fix up parent (this)
    if (m_firstChild == oldChildElem)
      m_firstChild = newChildElem;

    newChildElem.m_parentNode = this;
    oldChildElem.m_parentNode = null;
    newChildElem.m_nextSibling = oldChildElem.m_nextSibling;
    oldChildElem.m_nextSibling = null;

    // newChildElem.m_stylesheet = oldChildElem.m_stylesheet;
    // oldChildElem.m_stylesheet = null;
    return newChildElem;
  }
863040
function (oldChild) {
            var oldChildInNewTree = newNodeMap[oldChild.tagID];

            return oldChild.children && oldChildInNewTree && getParentID(oldChild) !== getParentID(oldChildInNewTree);
        }
1247623
ResolveSource replaceWithinCurrentParent(AbstractConfigValue old, AbstractConfigValue replacement) {
        if (ConfigImpl.traceSubstitutionsEnabled())
            ConfigImpl.trace("replaceWithinCurrentParent old " + old + "@" + System.identityHashCode(old)
                    + " replacement " + replacement + "@" + System.identityHashCode(old) + " in " + this);
        if (old == replacement) {
            return this;
        } else if (pathFromRoot != null) {
            Container parent = pathFromRoot.head();
            AbstractConfigValue newParent = parent.replaceChild(old, replacement);
            return replaceCurrentParent(parent, (newParent instanceof Container) ? (Container) newParent : null);
        } else {
            if (old == root && replacement instanceof Container) {
                return new ResolveSource(rootMustBeObj((Container) replacement));
            } else {
                throw new ConfigException.BugOrBroken("replace in parent not possible " + old + " with " + replacement
                        + " in " + this);
                // return this;
            }
        }
    }
217732
public function swapParentAndDelete(NodeContract $old_parent, NodeContract $new_parent)
    {
        $new_parent->replaceChild($old_parent->getIndex(), [$this]);

        return $this;
    }
963107
Node insertChildAt(Node newChild, int index) throws DOMException {
        if (newChild instanceof DocumentFragment) {
            NodeList toAdd = newChild.getChildNodes();
            for (int i = 0; i < toAdd.getLength(); i++) {
                insertChildAt(toAdd.item(i), index + i);
            }
            return newChild;
        }

        LeafNodeImpl toInsert = (LeafNodeImpl) newChild;
        if (toInsert.document != null && document != null && toInsert.document != document) {
            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
        }
        if (toInsert.isParentOf(this)) {
            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
        }

        if (toInsert.parent != null) {
            int oldIndex = toInsert.index;
            toInsert.parent.children.remove(oldIndex);
            toInsert.parent.refreshIndices(oldIndex);
        }

        children.add(index, toInsert);
        toInsert.parent = this;
        refreshIndices(index);

        return newChild;
    }
94154
public static PlanNode replaceChildren(PlanNode node, List<PlanNode> children)
    {
        for (int i = 0; i < node.getSources().size(); i++) {
            if (children.get(i) != node.getSources().get(i)) {
                return node.replaceChildren(children);
            }
        }
        return node;
    }
1074436
public void addChild(N child) {
    checkNotNull(child);
    tryRemoveFromOldParent(child);
    children.add(child);
    child.setParent(master);
  }
425994
public boolean setFourthChild(N newChild) {
		final N oldChild = this.nSouthEast;
		if (oldChild == newChild) {
			return false;
		}

		if (oldChild != null) {
			oldChild.setParentNodeReference(null, true);
			--this.notNullChildCount;
			firePropertyChildRemoved(3, oldChild);
		}

		if (newChild != null) {
			final N oldParent = newChild.getParentNode();
			if (oldParent != this) {
				newChild.removeFromParent();
			}
		}

		this.nSouthEast = newChild;

		if (newChild != null) {
			newChild.setParentNodeReference(toN(), true);
			++this.notNullChildCount;
			firePropertyChildAdded(3, newChild);
		}

		return true;
	}
408012
def new_children(self, **kwargs):
        """"""
        for k, v in kwargs.items():
            self.new_child(k, v)

        return self
8429
function replace(oldNode, newNode){
    return oldNode[PARENT_NODE] ? oldNode[PARENT_NODE].replaceChild(newNode, oldNode) : oldNode;
  }
1307347
@Override
	public boolean setChildAt(int index, N newChild) throws IndexOutOfBoundsException {
		final N oldChild = (index < this.children.length) ? this.children[index] : null;
		if (oldChild == newChild) {
			return false;
		}

		if (oldChild != null) {
			oldChild.setParentNodeReference(null, true);
			--this.notNullChildCount;
			firePropertyChildRemoved(index, oldChild);
		}

		if (newChild != null) {
			final N oldParent = newChild.getParentNode();
			if (oldParent != this) {
				newChild.removeFromParent();
			}
		}

		// set the element
		this.children[index] = newChild;

		if (newChild != null) {
			newChild.setParentNodeReference(toN(), true);
			++this.notNullChildCount;
			firePropertyChildAdded(index, newChild);
		}

		return true;
	}
1201027
public Node renameNode(Node n,
                           String namespaceURI,
                           String name)
                           throws DOMException{
        return n;
    }
999928
public ElemTemplateElement appendChild(ElemTemplateElement newChild)
  {

    int type = ((ElemTemplateElement) newChild).getXSLToken();

    if (Constants.ELEMNAME_SORT == type)
    {
      setSortElem((ElemSort) newChild);

      return newChild;
    }
    else
      return super.appendChild(newChild);
  }
71667
public Node<T> addChild(Node<T> child) {
        if (children == null) {
            children = new ArrayList<Node<T>>();
        }
        child.parent = this;
        children.add(child);

        return child;
    }
253706
def replaceChild(self, new_child: AbstractNode,
                     old_child: AbstractNode) -> AbstractNode:
        """"""
        return self._replace_child(new_child, old_child)
749455
public void addChild( LockedObject newChild ) {
        if (children == null) {
            children = new LockedObject[0];
        }
        int size = children.length;
        LockedObject[] newChildren = new LockedObject[size + 1];
        System.arraycopy(children, 0, newChildren, 0, size);
        newChildren[size] = newChild;
        children = newChildren;
    }
1146036
protected function replaceChild(Node $child, Node $replacement) {
    foreach ($this->getChildProperties() as $name => $value) {
      if ($child === $value) {
        $this->{$name} = $replacement;
        break;
      }
    }
    $replacement->parent = $this;
    $replacement->previous = $child->previous;
    $replacement->next = $child->next;
    if ($child->previous === NULL) {
      $this->head = $replacement;
    }
    else {
      $child->previous->next = $replacement;
    }
    if ($child->next === NULL) {
      $this->tail = $replacement;
    }
    else {
      $child->next->previous = $replacement;
    }
    $child->parent = NULL;
    $child->previous = NULL;
    $child->next = NULL;
    return $this;
  }