Encodings (4.3.3)
Every XML processor must accept UTF-8 and UTF-16; processors may accept others. A file
without an encoding declaration or byte order mark is UTF-8. Entities in UTF-16 must
start with a byte order mark. Anything else must be named in the
encoding pseudo-attribute of the XML or text declaration. It is a fatal
error for a declaration to contradict the actual encoding, and for bytes to be
invalid in the encoding in use.
Autodetection (Appendix F)
Before reading the declaration, the first bytes show which family of encodings to try:
| First bytes | Encoding |
|---|---|
00 00 FE FF | UTF-32 big-endian with a byte order mark |
FF FE 00 00 | UTF-32 little-endian with a byte order mark |
FE FF | UTF-16 big-endian with a byte order mark |
FF FE | UTF-16 little-endian with a byte order mark |
EF BB BF | UTF-8 with a byte order mark |
00 00 00 3C | UCS-4 big-endian, no byte order mark |
3C 00 00 00 | UCS-4 little-endian, no byte order mark |
00 00 3C 00 | UCS-4 unusual byte order (2143) |
00 3C 00 00 | UCS-4 unusual byte order (3412) |
00 3C 00 3F | UTF-16 big-endian, no byte order mark |
3C 00 3F 00 | UTF-16 little-endian, no byte order mark |
3C 3F 78 6D | A family of ASCII-compatible encodings; read the declaration |
4C 6F A7 94 | EBCDIC (<?xm); read the declaration to find the code page |
The viewer on this site reads UTF-8, UTF-16 and UTF-32 (with or without a mark), the single-byte encodings a browser knows by name, and EBCDIC code pages 037 and 500. An encoding it cannot decode is reported and the file is shown as UTF-8.
Media types (RFC 7303)
| Media type | Use |
|---|---|
application/xml | General XML |
text/xml | The same, as a human-readable text type |
application/xml-dtd | External DTD subsets and parameter entities |
application/xml-external-parsed-entity | External parsed entities |
suffix +xml | Any XML-based format, such as image/svg+xml |
The usual extension is .xml; external subsets use .dtd and
entities .ent or .mod.