<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLDocument/xmlData(options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLDocument(im)XMLDataWithOptions:"
  },
  "title" : "xmlData(options:)"
}
-->

# xmlData(options:)

Returns the XML string representation of the receiver—that is, the entire document—encapsulated in a data object.

```
func xmlData(options: XMLNode.Options = []) -> Data
```

## Parameters

`options`

One or more options (bit-OR’d if multiple) to affect the output of the document; see Constants for the valid output options.

## Discussion

The encoding used is based on the value returned from [`characterEncoding`](/documentation/Foundation/XMLDocument/characterEncoding).

---

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)