---
title: "setChildren(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/xmlelement/setchildren(_:)"
---

# setChildren(_:)

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

## Declaration

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

## Parameters

- `children`: An array of NSXMLElement objects or doc://com.apple.foundation/documentation/Foundation/XMLNode objects of kinds doc://com.apple.foundation/documentation/Foundation/XMLNode/Kind-swift.enum/element, doc://com.apple.foundation/documentation/Foundation/XMLNode/Kind-swift.enum/processingInstruction, doc://com.apple.foundation/documentation/Foundation/XMLNode/Kind-swift.enum/text, or doc://com.apple.foundation/documentation/Foundation/XMLNode/Kind-swift.enum/comment.

## Discussion

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

## See Also

### Manipulating Child Elements

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