XML File Format (.xml)
An XML file holds data as nested elements identified by opening and closing tags, optionally carrying attributes, namespaces and a schema that validates its structure.
XML at a glance#
| Full name | Extensible Markup Language |
|---|---|
| File extension | .xml |
| Category | Data Files |
| Developer | World Wide Web Consortium (W3C) |
| First released | 1998 |
| MIME types | application/xmltext/xml |
| Compression | Uncompressed |
| Specification | Extensible Markup Language (XML) 1.0 (Fifth Edition) |
| FileFlip support | FileFlip reads and writes this format |
What a .xml file can hold#
These are the things a XML file either supports or does not, and they are what decides whether a conversion keeps everything or quietly drops something.
| Embedded metadata | Yes |
|---|---|
| Human readable | Yes |
| Comments | Yes |
| Schema or validation | Yes |
Strengths and limitations of XML#
What XML does well
- Namespaces let a document mix vocabularies from different schemas without tag names colliding
- DTDs and XML Schema can validate a document's structure before a program ever touches it
- Attributes and elements give two distinct ways to attach data to a node, where JSON has only one
Where XML falls short
- Verbose compared to JSON, since every element needs a matching closing tag
- The attribute-versus-element choice is a judgment call with no single right answer, so XML documents from different authors are structurally inconsistent
- Parsing safely requires disabling external entity resolution, or the parser is exposed to XXE attacks
- No native array type, so a repeated element is how XML represents a list, and that's a convention rather than a rule the spec enforces
Use XML where a schema needs to validate the document's shape, or the receiving system is a SOAP service or a Java or .NET stack that expects it.
Convert XML to JSON when a web API or a JavaScript codebase needs to consume the data, since neither has native use for XML's attributes or namespaces.
How to open a .xml file#
A .xml file opens in the programs below, grouped by the platform you are on. If you would rather not install anything, FileFlip converts XML into a format your machine already opens, and it does it in the browser tab rather than on a server.
| Platform | Programs that open it |
|---|---|
| Windows | VS Code, Notepad++, Microsoft Excel |
| macOS | VS Code, Sublime Text, TextEdit |
| Linux | VS Code, vim, gedit |
| Web | FileFlip |
XML questions people ask#
What happens to XML attributes when converting to JSON?
XML lets a node carry data two ways, as an attribute on its tag or as a nested element, and JSON only has one, a plain key. Converting XML to JSON has to fold attributes into ordinary keys, usually with a prefix like an @ sign, and that convention differs between converters because there's no standard mapping between the two.
Does converting XML to JSON keep the namespaces?
Not meaningfully. XML namespaces disambiguate elements from different vocabularies using a URI, and JSON keys have no namespace concept, so a converter either drops the namespace prefix, folds it into the key name as text, or ignores it. Either way, the semantic distinction the namespace was providing is gone from the JSON output.
How does XML represent a list if it has no array type?
XML has no array syntax, so a list is written as several sibling elements sharing the same tag name, and it's the reader's job to know that repetition means a list rather than a coincidence. A single item in what should be a list looks identical to a field that only ever has one value, which is a common source of bugs when converting XML to JSON, since a converter has to guess whether to produce an array or a single object.
Do XML comments survive conversion to JSON or YAML?
No. XML comments, written inside angle-bracket-bang markers, aren't part of the data model a converter reads, so they're discarded during conversion to JSON, YAML or any other format. The same is true of processing instructions and the DOCTYPE declaration.
Converting XML files#
Convert XML to another format
Convert another format to XML
Every conversion runs inside your browser. The file is read from your disk, the work happens on your own machine, and nothing is uploaded. How FileFlip works names the engine behind each family and how to verify that for yourself.