<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLNode/rootDocument",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLNode(py)rootDocument"
  },
  "title" : "rootDocument"
}
-->

# rootDocument

Returns the [`XMLDocument`](/documentation/Foundation/XMLDocument) object containing the root element and representing the XML document as a whole.

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

## 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`.

---

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)