---
title: characterEncoding
framework: foundation
role: symbol
role_heading: Instance Property
path: foundation/xmldocument/characterencoding
---

# characterEncoding

Sets the character encoding of the receiver to encoding,

## Declaration

```swift
var characterEncoding: String? { get set }
```

## Parameters

- `encoding`: A string that specifies an encoding; it must match the name of an IANA character set. See http://www.iana.org/assignments/character-sets for a list of valid encoding specifiers.

## Discussion

Discussion Typically the encoding is specified in the XML declaration of a document that is processed, but it can be set at any time. If the specified encoding does not match the actual encoding, parsing of the document might fail.

## See Also

### Managing Document Attributes

- [documentContentKind](foundation/xmldocument/documentcontentkind.md)
- [dtd](foundation/xmldocument/dtd.md)
- [isStandalone](foundation/xmldocument/isstandalone.md)
- [mimeType](foundation/xmldocument/mimetype.md)
- [version](foundation/xmldocument/version.md)
