---
title: "insertChild(_:at:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/xmlelement/insertchild(_:at:)"
---

# insertChild(_:at:)

Inserts a new child node at a specified location in the receiver’s list of child nodes.

## Declaration

```swift
func insertChild(_ child: XMLNode, at index: Int)
```

## Parameters

- `child`: An XML node object to be inserted as a child of the receiver.
- `index`: An integer identifying a position in the receiver’s list of children. An exception is raised if index is out of bounds.

## Discussion

Discussion Insertion of the node increments the indexes of sibling nodes after it.

## See Also

### Manipulating Child Elements

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