---
title: "xmlData(options:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/xmldocument/xmldata(options:)"
---

# xmlData(options:)

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

## Declaration

```swift
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

Discussion The encoding used is based on the value returned from characterEncoding.

## See Also

### Writing a Document as XML Data

- [xmlData](foundation/xmldocument/xmldata.md)
