XML file signature
Magic number at the start of the file · <?xml
XML documents usually open with the declaration <?xml version=..., i.e. the bytes 3C 3F 78 6D 6C. A UTF-8 byte-order mark EF BB BF may appear first. Many formats (SVG, RSS, plist) are XML and start the same way.
What this magic number means
A magic number is a short, fixed run of bytes at a known position that tells a program what a file really is, no matter what the filename says. If a file starts with the bytes 3C 3F 78 6D 6C 20 (the text <?xml ), the file opens with an XML declaration. It says the file is XML text; it does not say which XML format. SVG drawings, RSS feeds, GPX tracks, KML overlays, COLLADA scenes and Apple plists all begin with these same bytes, and the root element on the next line is what actually names the format.
This is why so many unrelated file types share one header. GPS tracks (GPX), Google Earth overlays (KML), COLLADA 3D scenes (DAE), FictionBook e-books (FB2), EPUB package manifests (OPF) and XSPF playlists are all XML documents, so the first bytes tell you the syntax, not the format. The root element on the next line is what actually names the format: <gpx>, <kml>, <COLLADA> and so on.
Because XML is text, the declaration is optional. A perfectly valid XML file can begin straight with its root element, so a missing 3C 3F 78 6D 6C does not prove the file is not XML.
Put the two together and this is a signature that fails in both directions: it can be present on a file that is not the format you want, and absent on a file that is. It is a useful first filter and a poor last word.
What each byte of 3C 3F 78 6D means
Here is the signature byte by byte, the way a hex editor shows it: the position in the file, the value in hex and in decimal, and the character that value stands for in ASCII. Bytes with no printable character show a dot.
| Byte offset | Hex | Decimal | ASCII |
|---|---|---|---|
| 0 | 3C | 60 | < |
| 1 | 3F | 63 | ? |
| 2 | 78 | 120 | x |
| 3 | 6D | 109 | m |
| 4 | 6C | 108 | l |
| 5 | 20 | 32 |
Formats that use the 3C 3F 78 6D signature
These file types in our database carry this signature:
It is also seen in: RSS, XHTML, MusicXML.
How to check a file's signature
You can read the bytes of any file yourself. They are shown in hex, the same way this page lists them.
Linux & macOS
- xxd -l 16 example.xml
- hexdump -C -n 16 example.xml
- file example.xml
Windows (PowerShell)
- Format-Hex -Path example.xml -Count 16
Python
- open("example.xml","rb").read(6).hex()
In your browser
- Drop the file into the WhatFileType identifier, which reads the signature without uploading it.
Frequently asked questions
What is the XML file signature?
An XML document normally opens with the declaration <?xml version="1.0"?>, whose first five bytes are 3C 3F 78 6D 6C. A UTF-8 byte order mark, EF BB BF, may sit in front of it. The W3C specification makes the declaration optional, so XML has no signature that is guaranteed to be there.
Do the bytes 3C 3F 78 6D 6C identify a specific format?
No, only a syntax. SVG images, RSS and Atom feeds, GPX tracks, KML overlays, COLLADA scenes, FictionBook e-books, XSPF playlists and the parts inside a DOCX all start with the same five bytes. The root element on the following line is what names the format: <svg>, <rss>, <gpx>, <kml> and so on.
Why does my XML file not start with <?xml?
Because the declaration is optional. XML 1.0 recommends it but does not require it for a UTF-8 document, so many generators omit it and the file begins straight with its root element. That is valid XML, and a signature check that insists on the prolog will wrongly reject it.
How do I tell which XML format a file is?
Read the root element and its namespace, not the first bytes. head -c 300 example.xml on Linux or macOS shows both, and file example.xml goes one step further and names the format for the common ones. In code, parse the document and inspect the document element rather than comparing bytes.
Related signatures
Sources
Reuse this signature
This entry is part of the WhatFileType file signature reference, published under a CC BY 4.0 licence with the full provenance for every entry, a copy-paste embed and a JSON export. Credit WhatFileType and the data is yours to republish.