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

# setChildren(_:)

Sets all child nodes of the receiver at once, replacing any existing children.

```
func setChildren(_ children: [XMLNode]?)
```

## Parameters

`children`

An array of `NSXMLElement` objects or [`XMLNode`](/documentation/Foundation/XMLNode) objects of kinds [`XMLNode.Kind.element`](/documentation/Foundation/XMLNode/Kind-swift.enum/element), [`XMLNode.Kind.processingInstruction`](/documentation/Foundation/XMLNode/Kind-swift.enum/processingInstruction), [`XMLNode.Kind.text`](/documentation/Foundation/XMLNode/Kind-swift.enum/text), or [`XMLNode.Kind.comment`](/documentation/Foundation/XMLNode/Kind-swift.enum/comment).

## Discussion

Send this message with `children` as `nil` to remove all child nodes.

---

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)