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

# replaceChild(at:with:)

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

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

The replaced XML node object is released upon removal.

---

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)