---
title: "replaceChild(at:with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/xmlelement/replacechild(at:with:)"
---

# replaceChild(at:with:)

Replaces a child node at a specified location with another child node.

## Declaration

```swift
func replaceChild(at index: Int, with node: XMLNode)
```

## Parameters

- `index`: An integer identifying a position in the receiver’s list of children. An exception is raised if index is out of bounds.
- `node`: An XML node object that will replace the current child.

## Discussion

Discussion The replaced XML node object is released upon removal.

## See Also

### Manipulating Child Elements

- [addChild(_:)](foundation/xmlelement/addchild(_:).md)
- [insertChild(_:at:)](foundation/xmlelement/insertchild(_:at:).md)
- [insertChildren(_:at:)](foundation/xmlelement/insertchildren(_:at:).md)
- [removeChild(at:)](foundation/xmlelement/removechild(at:).md)
- [setChildren(_:)](foundation/xmlelement/setchildren(_:).md)
- [normalizeAdjacentTextNodesPreservingCDATA(_:)](foundation/xmlelement/normalizeadjacenttextnodespreservingcdata(_:).md)
