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

# replaceChild(at:with:)

Replaces the child node of the receiver located at a specified position in its array of children with another node.

## Declaration

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

## Parameters

- `index`: An integer identifying a position in the receiver’s array of children. If index is less than zero or greater than the number of children minus one, an out-of-bounds exception is raised.
- `node`: An doc://com.apple.foundation/documentation/Foundation/XMLNode object to replace the one at index; it must represent a comment, a processing instruction, or the root element.

## Discussion

Discussion The removed NSXMLNode object is autoreleased.

## See Also

### Adding and Removing Child Nodes

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