---
title: "init(rootElement:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/xmldocument/init(rootelement:)"
---

# init(rootElement:)

Returns an NSXMLDocument object initialized with a single child, the root element.

## Declaration

```swift
init(rootElement element: XMLElement?)
```

## Parameters

- `element`: An doc://com.apple.foundation/documentation/Foundation/XMLElement object representing an XML element.

## Return Value

Return Value An initialized NSXMLDocument object, or  nil if initialization fails for any reason.

## See Also

### Initializing NSXMLDocument Objects

- [init(contentsOf:options:)](foundation/xmldocument/init(contentsof:options:).md)
- [init(data:options:)](foundation/xmldocument/init(data:options:).md)
- [init(xmlString:options:)](foundation/xmldocument/init(xmlstring:options:)-65m2r.md)
- [replacementClass(for:)](foundation/xmldocument/replacementclass(for:).md)
