---
title: rootDocument
framework: foundation
role: symbol
role_heading: Instance Property
path: foundation/xmlnode/rootdocument
---

# rootDocument

Returns the XMLDocument object containing the root element and representing the XML document as a whole.

## Declaration

```swift
var rootDocument: XMLDocument? { get }
```

## Discussion

Discussion If the receiver is a standalone node (that is, a node at the head of a detached branch of the tree), this method returns nil.

## See Also

### Navigating the Tree of Nodes

- [parent](foundation/xmlnode/parent.md)
- [child(at:)](foundation/xmlnode/child(at:).md)
- [childCount](foundation/xmlnode/childcount.md)
- [children](foundation/xmlnode/children.md)
- [next](foundation/xmlnode/next.md)
- [nextSibling](foundation/xmlnode/nextsibling.md)
- [previous](foundation/xmlnode/previous.md)
- [previousSibling](foundation/xmlnode/previoussibling.md)
- [detach()](foundation/xmlnode/detach().md)
