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

# insertChild(_:at:)

Inserts a node object at specified position in the receiver’s array of children.

## Declaration

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

## Parameters

- `child`: The doc://com.apple.foundation/documentation/Foundation/XMLNode object to be inserted. The added node must be an NSXMLNode object representing a comment, processing instruction, or the root element.
- `index`: An integer specifying the index of the children array to insert child. The indexes of children after the new child are incremented. If index is less than zero or greater than the number of children, an out-of-bounds exception is raised.

## See Also

### Adding and Removing Child Nodes

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