---
title: "setRootElement(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/xmldocument/setrootelement(_:)"
---

# setRootElement(_:)

Set the root element of the receiver.

## Declaration

```swift
func setRootElement(_ root: XMLElement)
```

## Parameters

- `root`: An doc://com.apple.foundation/documentation/Foundation/XMLNode object that is to be the root element.

## Discussion

Discussion As a side effect, this method removes all other children, including NSXMLNode objects representing comments and processing-instructions.

## See Also

### Managing the Root Element

- [rootElement()](foundation/xmldocument/rootelement().md)
