<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLElement/insertChild(_:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLElement(im)insertChild:atIndex:"
  },
  "title" : "insertChild(_:at:)"
}
-->

# insertChild(_:at:)

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

```
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

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)