Start here
Quick answer: pick by who validates the file
If every program that reads the file is yours, use YAML: it costs far less markup per byte and it is easier for a human to edit under time pressure. If anybody else validates the file — a vendor, a regulator, an interoperability standard, a signature — use XML, because XML brings a published data model, a schema language, a path syntax and a canonical serialisation, and YAML brings none of those. The bracket count is the least interesting difference between them.
The sentence that explains almost every other difference: XML standardised the tree; YAML standardised the way you write a tree down. After parsing, an XML processor owes you a defined abstract object — the Information Set, eleven kinds of item with named properties — plus optional contracts (XSD, XPath, XSLT, Canonical XML) that are themselves specifications with conformance clauses. After parsing, a YAML processor owes you a graph of nodes and scalars, and then your configuration decides what a value is: which schema resolves an unquoted scalar, which yq dialect queries it, which emitter writes it back.
country: NO # YAML 1.1 resolver: false. YAML 1.2: the string "NO".
version: 1.10 # both: the number 1.1, not the text 1.10.
release: 2026.42 # a float, so 2026.40 would print as 2026.4.
timeout: 30m # a string here, and in XML the same string.
# In XML all four stay text until a schema says otherwise:
# <release>2026.42</release> is the string "2026.42" with no type asserted.The first three lines are the Norway problem, which has ended more YAML migrations than any stylistic complaint about it. Nothing is malformed, nothing errors, and the value the program receives is not the value you wrote — a type change caused by the format, not by an edit. Quote anything whose shape matters, or move the decision into a schema.
| You are writing… | Use | Because |
|---|---|---|
| Kubernetes, CI or deployment manifests | YAML | The ecosystem, the diff tools and the templating already assume it. |
| A config file a human edits by hand | YAML | Roughly half the bytes for the same tree; less to type and less to misread. |
| An interchange format a vendor consumes | XML plus a published XSD | They can test your document without reading your source code. |
| Prose with markup inside it | XML | Mixed content is a first-class Infoset feature; YAML has no slot for ordering between text and elements. |
| A payload that must be signed | XML | Canonical XML gives a deterministic serialisation to sign. YAML has no canonical form. |
| Records with no nesting at all | CSV or JSON | Flat rows do not need a markup metalanguage in either format. |
| Config whose types matter | Either, with a schema | Untyped YAML and unvalidated XML have the same hole; only one has a standard filler. |
Everything below earns those rows. The next section writes one real document four ways so the losses are numbers you can check rather than claims; the sections after that go down through the model, the vocabulary gaps, whitespace, naming, types, size, security and tooling, and end with the migration failure catalogue and the fidelity matrix.
Worked example
The same document written four ways
Everything is argued against one document, so that the byte counts, the losses and the surprises are all checkable. It is a deployment manifest, which is the genre that has been migrating from XML to YAML for a decade, and it contains the features that matter: a release identifier that looks like a number, an aliased block, a nested sequence, environment variables, a multi-line note, a comment, and enough metadata to be carried in attributes.
# Release manifest for checkout-api
%YAML 1.2
---
release:
id: 2026.42
name: "checkout-api"
channel: stable
rollback: &rb
strategy: blue-green
window: 30m
services:
- name: api
image: "registry.example.com/checkout-api:2026.42"
ports: [8080, 8443]
replicas: 3
rollback: *rb
- name: worker
image: "registry.example.com/checkout-worker:2026.42"
replicas: 2
env:
LOG_LEVEL: info
FEATURE_X: "yes"
notes: |
Roll back if the p99 latency
exceeds 400 ms.
...545 bytes, 26 lines. Measured under the recipe in the bytes section: 334 bytes are structure (indentation, key text, colons, the comment, the directive, the two document markers and the dash indicators) and 211 bytes are scalar content. Note three things already: id resolves to a float under the core schema, FEATURE_X is deliberately quoted so that it cannot, and rollback is one node with two incoming edges.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Release manifest for checkout-api -->
<release id="2026.42" name="checkout-api" channel="stable"
xmlns="https://example.com/manifest/1"
xmlns:ops="https://example.com/ops/1">
<rollback>
<strategy>blue-green</strategy>
<ops:window unit="minutes">30</ops:window>
</rollback>
<services>
<service kind="api">
<image>registry.example.com/checkout-api:2026.42</image>
<ports>
<port>8080</port>
<port>8443</port>
</ports>
<replicas>3</replicas>
<rollback>
<strategy>blue-green</strategy>
<ops:window unit="minutes">30</ops:window>
</rollback>
</service>
<service kind="worker">
<image>registry.example.com/checkout-worker:2026.42</image>
<replicas>2</replicas>
<env name="LOG_LEVEL">info</env>
<env name="FEATURE_X">yes</env>
</service>
</services>
<notes>Roll back if the <em>p99</em> latency exceeds 400 ms.</notes>
<?ops hint="manual approval before the second batch"?>
</release>1,067 bytes, 21 elements, 21 start tags and 21 end tags, 10 attributes plus 2 namespace declarations, one comment, one processing instruction and one XML declaration: 739 bytes of markup, 158 bytes of whitespace-only text nodes, 170 bytes of payload. The alias is gone, because XML has no way to say two subtrees are the same node, and notes is mixed content, because YAML has no way to say that.
Now the two round trips. Neither is produced by a tool on this site — FmtTools has no XML converter — and neither is presented as canonical. They are what a generic converter with rules on the table produces: attributes and namespace declarations become keys with a synthetic prefix, repeated children become sequences, and text content becomes a key called _text.
release:
_id: "2026.42"
_name: "checkout-api"
_channel: "stable"
_xmlns: "https://example.com/manifest/1"
_xmlns_ops: "https://example.com/ops/1"
rollback:
strategy: blue-green
ops:window:
_unit: "minutes"
_text: "30"
services:
service:
- _kind: "api"
image: registry.example.com/checkout-api:2026.42
ports:
port:
- "8080"
- "8443"
replicas: "3"
rollback:
strategy: blue-green
ops:window:
_unit: "minutes"
_text: "30"
- _kind: "worker"
image: registry.example.com/checkout-worker:2026.42
replicas: "2"
env:
- _name: "LOG_LEVEL"
_text: info
- _name: "FEATURE_X"
_text: yes
notes: "Roll back if the p99 latency exceeds 400 ms."856 bytes — 311 more than the YAML that started this, because 11 synthetic keys were invented and the aliased rollback block was duplicated. Three silent changes: the comment and the processing instruction vanished, the em element inside notes was flattened into a string, and _text: yes is now an unquoted plain scalar, which a YAML 1.1 resolver turns into the boolean true.
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns="https://example.com/manifest/1">
<release>
<id>2026.42</id>
<name>checkout-api</name>
<channel>stable</channel>
<rollback xmlns="https://example.com/manifest/1/rollback">
<strategy>blue-green</strategy>
<window>30m</window>
</rollback>
<services>
<item xmlns="https://example.com/manifest/1/services">
<name>api</name>
<image>registry.example.com/checkout-api:2026.42</image>
<ports>
<item>8080</item>
<item>8443</item>
</ports>
<replicas>3</replicas>
<rollback>
<strategy>blue-green</strategy>
<window>30m</window>
</rollback>
</item>
<item>
<name>worker</name>
<image>registry.example.com/checkout-worker:2026.42</image>
<replicas>2</replicas>
<env>
<LOG_LEVEL>info</LOG_LEVEL>
<FEATURE_X>yes</FEATURE_X>
</env>
</item>
</services>
<notes>Roll back if the p99 latency exceeds 400 ms.</notes>
</release>
</manifest>1,101 bytes, 27 elements, three namespace declarations and four generic item element names. This is the failure mode of a writer that derives a namespace per nesting level: the tree is still well-formed, and every path expression ever written against it is now wrong, because an element with no prefix in a document with a default namespace is in that namespace, not in the empty one.
| Document | Bytes | Lines | Structural bytes | Payload bytes | What changed |
|---|---|---|---|---|---|
| YAML, source | 545 | 26 | 334 | 211 | none — this is the baseline |
| XML, source | 1,067 | 33 | 897 (markup plus whitespace text) | 170 | alias expanded, mixed content introduced |
| XML to YAML, round trip | 856 | 34 | n/a | n/a | 11 synthetic keys, comment and PI dropped, yes unquoted |
| YAML to XML, round trip | 1,101 | 37 | n/a | n/a | 3 namespace declarations, 4 generic item names, block scalar folded |
Structural bytes for the two round-tripped documents are not quoted because the classification depends on whether you count a synthetic key as structure or as payload; the raw totals and the specific losses are the parts that are load-bearing.
The real difference
The asymmetry: one format has a standardised tree
Ask which is better and you will be handed the same object twice, with one of them wearing angle brackets. That comparison is beside the point: nobody dropping XML for YAML is saving keystrokes, and nobody keeping XML is spending them for pleasure. XML and YAML both describe trees, and only one of them has a standardised tree. The other has a standardised way of writing one down.
XML 1.0 (Fifth Edition) §2.1 makes well-formedness a property of the text: a document must match production [1], satisfy every well-formedness constraint, and every entity it references must itself be well-formed. The XML Information Set then describes, normatively, what a processor hands you after the text is consumed: document, element, attribute, namespace, text, processing instruction, comment, document type declaration, entity reference, notation and unparsed entity items, each with named properties such as the [namespace name] of an element and the [normalized value] of an attribute. That is a data model, not a syntax, and it is what makes the following two documents the same fact:
<release channel="stable"><notes>ok</notes></release>
<release channel='stable' >
<notes>ok</notes>
</release>Different bytes, same element items, same attribute item with one [normalized value], same two children in the same order — a conformant processor is obliged to hand you the same information set either way. YAML has an equivalent guarantee at its serialization layer, and then loses it one level up: change the resolver schema and the type of a scalar changes, so two conformant readers can disagree about what a value is, not merely about how it was spelled.
On top of the model the stack keeps building, and every layer is a published specification with a conformance clause rather than a product: XML Schema Parts 1 and 2 constrain the information set and assign types to it — Part 1 §2.2 is explicit that building on the Infoset gives schemas "a priori guarantees of well-formedness" and namespace conformance. XPath 3.1 standardises how you address a node, XSLT 3.0 how you rewrite it, XPointer how to point inside one, and Canonical XML supplies the deterministic serialisation that makes a signed payload possible at all: you cannot sign text when two conformant writers may disagree about attribute order.
YAML standardises less, and it is worth being exact rather than disparaging. YAML 1.2.2 §3.2.1 defines a representation as "a rooted, connected, directed graph of tagged nodes", permits cycles and multiple incoming edges, and splits the model into a serialization tree (§3.2.2), where order and anchors exist, and a presentation stream (§3.2.3), where indentation, styles and comments exist. That is a real model, and in one respect it is stronger than XML: an alias in YAML denotes node identity, which XML simply cannot express. What YAML does not have is anything above that model — no standard schema language (§10 offers three recommended tag-resolution schemas and §10.4 points at "other schemas"), no standard path syntax, no standard transformation language, no canonical form, no fragment identifier.
- Information Set (Infoset)
- The normative abstract model of what an XML processor gives you: 11 item kinds with named properties, independent of how the document was written.
- Well-formed vs valid
- Well-formed is XML 1.0 syntax, which a processor must enforce. Valid means conforming to a named grammar, which it need not even look at.
- Representation graph
- YAML 1.2.2 §3.2.1: a rooted directed graph of tagged nodes, permitted to contain cycles — more expressive than a tree, less standardised above it.
- Presentation stream
- The text layer of YAML: indentation, block styles, comments, directives. The spec says explicitly that indentation is a presentation detail.
- Tag resolution
- How a plain YAML scalar becomes int, bool or str. Decided by a chosen schema, not by the document; §3.3.2 admits it is application-specific.
- xsi:type
- The XML instance attribute that asserts a type for an element; Part 1 §2.6.1 says its value is a QName resolved against a type definition.
- Canonical form
- A deterministic serialisation of an Infoset. XML has two published ones; YAML has none, which is why YAML signatures wrap the data in JSON first.
Vocabulary gaps
What each direction cannot say
The useful way to plan a conversion is not "what will my tool do" but "which features of one model have no slot in the other". Below is that list, feature by feature, with the mechanism each format uses and what a converter is forced to decide.
| Feature | How it works at home | What the other format must invent or drop |
|---|---|---|
| XML attributes | An unordered set of unique names, each with one normalised string value; no nesting, no markup. | A key that cannot collide with a child element, so converters prefix them; two attributes named id in different namespaces collapse unless the prefix includes the URI. |
| XML namespace declarations | A URI identity plus a prefix whose scope runs from the start-tag to the matching end-tag. | Nothing. A round-tripped document either loses the prefix mapping or stores xmlns as an ordinary scalar, which no longer scopes anything. |
| Mixed content | Text and elements interleaved as ordered children of one element — the reason XML is a markup language. | Either a concatenation that loses the interleaving, or an invented list of typed fragments. YAML mappings cannot express ordering between siblings of different kinds. |
| Processing instructions | Application-directed markup, [16], with a PITarget and data. | Dropped by most converters. YAML has no target-directed markup at all; comments are inert and §3.2.3.3 puts them in the presentation layer. |
| DTD and entity declarations | A grammar plus named substitutions, including notations and unparsed entities. | Dropped entirely. This is where the schema contract goes, so the migration trades a published constraint for an undocumented convention. |
| xsi:type assertions | A per-instance claim that this element is of that schema type, Part 1 §2.6.1. | A YAML tag, which is the right mechanism and almost never used, so the type usually becomes a string and a downstream parser re-guesses it. |
| YAML anchors and aliases | Node identity: one node reachable from two places, permitted to form cycles, §3.2.1. | Duplicated subtrees, or XLink attributes that mean nothing to a plain processor, or internal general entities that substitute text rather than nodes. |
| YAML tags | Explicit type assertions plus the extension mechanism §3.3.3 says must be recognized to be valid. | Either an attribute holding the URI, or a naming convention. Both make the tagged value look like data to a processor that cannot see the type. |
| Explicit keys | The ? indicator, production [5], permitting a key that is a sequence, a mapping or a long scalar. | An element name. XML names cannot contain structure, so a mapping keyed by coordinates has no faithful XML shape at all. |
| Multi-document streams | --- and ... markers, §9.1-9.2, plus %YAML and %TAG directives per document. | Either a wrapper element with a repeated child, which changes every path, or one file per document, which changes the transport. |
| Block scalars | Literal and folded styles with indentation and chomping indicators, §8.1. | A text node holding newlines, plus a convention for trailing newline handling that XML does not have. xml:space preserves the bytes; it does not preserve the intent that they are verbatim. |
| Merge keys | The 1.1 << convention, a working draft rather than part of the core schema. | Nothing. The merged keys are simply present or absent, and whether they were inherited is lost. |
Mixed content, in two lines
One row deserves more than a cell, because it is where a conversion does not degrade the document but refutes it. XML can put an element in the middle of a sentence and keep the order; YAML cannot put anything in the middle of a scalar.
# XML, normatively ordered children:
# <notes>Roll back if the <em>p99</em> latency exceeds 400 ms.</notes>
# Option 1 — what every converter does: the element becomes text.
notes: "Roll back if the p99 latency exceeds 400 ms."
# Option 2 — the ordering becomes data, and only your code knows the convention.
notes:
- text: "Roll back if the "
- em: "p99"
- text: " latency exceeds 400 ms."Option 1 destroys which words were emphasised. Option 2 keeps everything and invents a vocabulary: it is a YAML encoding of an XML idea, and no other tool will read it as markup. XML resolves the question in the model instead — the Infoset orders the children of one element, and a schema declares the element mixed — which is why the row above says lossy rather than configurable.
The shape neither format can say
? [latitude, longitude]
: name: Reykjavik
tz: UTC
cells:
? [2026, 11, 12]
: 41Legal YAML: production [5] makes the question mark the mapping-key indicator, so any node may be a key, and §3.2.1 requires keys to be unique and unordered. XML cannot hold this shape at all, because an element or attribute name must be an XML name, which excludes structure. The reverse gap is the same size: a YAML scalar containing a paragraph in which an element appears mid-sentence is not a scalar in XML either, and XML has a normative word for the distinction — element content versus mixed content — that YAML does not.
§6.1 against §2.10
Whitespace: two different contracts
Both formats let whitespace change meaning, and the mechanisms are so different that the bugs they cause are never the same bug. YAML makes indentation structural and then apologises for it. XML makes whitespace ordinary data and then asks a schema what to do with it.
The YAML rule is unambiguous and most developers have never read it. §6.1 says indentation is zero or more space characters at the start of a line and that, "to maintain portability, tab characters must not be used in indentation, since different systems treat tabs differently". The same section adds the sentence that should govern every style guide: "The amount of indentation is a presentation detail and must not be used to convey content information." And §6.2 permits tabs as separation space between tokens, which is why key:<tab>value parses while <tab>key: value inside a nested block does not.
# A: the note is a folded paragraph in a key called notes
notes: >
roll back if the p99
latency exceeds 400 ms
if ops are busy
# B: one space removed from the third content line
notes: >
roll back if the p99
latency exceeds 400 ms
if ops are busyIn A every content line is indented past the block scalar indicator, so folding joins all four lines into one sentence. In B the last line is indented less than the first, which §6.5 treats as a more-indented line boundary condition rather than a paragraph continuation — the same words, with one space deleted, produce a different string. Nothing is ill-formed in either case and no validator will mention it, because this is what the language means.
XML takes the opposite route: whitespace inside an element is text, and text items are part of the normative information set. That is why the manifest above contains 31 whitespace-only text nodes totalling 158 bytes — 15 per cent of the file — and why two APIs reading the same document disagree about what it contains.
<ports>
<port>8080</port>
</ports>Between the ports tags there is a text item containing a newline and two spaces, and it is in the information set like any other. A DOM or ElementTree walk that ignores whitespace-only text sees one child; one that obeys the Infoset sees three. XML 1.0 §2.10 lets an application that intends a human-readable result choose to ignore whitespace in element content, and promises only this: a validating processor MUST also inform the application which characters constitute white space appearing in element content — so the answer depends on a schema or DTD having been loaded.
Between those two choices, pretty-printing changes the value of a text node. The classic failure is the element that sometimes has children and sometimes has only indentation: <window>30</window> survives either opinion, and <notes> text </notes> does not. Measured directly: parsing the manifest with the Python standard library's ElementTree and re-serialising produces 1,068 bytes in which the comment, the processing instruction and the XML declaration have all vanished and both namespace prefixes have been regenerated as ns0 and ns1, while all 31 whitespace-only text nodes survive exactly as written. The part the standard insists on keeping is the indentation nobody wanted; the part that carried the intent is what a perfectly conformant library dropped without an error.
Two mechanisms exist because this is unresolved. xml:space is the special attribute §2.10 introduces to signal that whitespace in that element should be preserved — inherited, so xml:space="preserve" on a root covers the document. And §3.3.3 normalises attribute values, which is why a base64 payload in an attribute behaves differently from the same payload in element content: a literal line break inside an attribute value becomes a space, while a numeric character reference to the same newline survives as a real line feed. See Base64 for the encoding side of that trap.
| Question | YAML 1.2.2 | XML 1.0 (Fifth Edition) |
|---|---|---|
| Are tabs legal for indentation? | No — §6.1 forbids them in indentation, while §6.2 allows them as separation space. | Yes — #x9 is one of the three allowed whitespace characters, production [3]. |
| Is indentation semantic? | Yes for block collections and block scalars, which contradicts the presentation-detail sentence in the same section. | No, never: indentation is text, and text is payload. |
| Does whitespace-only content change a value? | Only inside a block scalar, where folding and chomping decide it, §8.1. | Yes, and whether that matters depends on the declared content model, §2.10. |
| Is there a preservation signal? | No signal needed for block scalars, none available for plain ones. | xml:space, inherited, defined in §2.10 and deliberately not a conformance requirement for all applications. |
| Does the standard model keep it? | The presentation stream keeps styles; the serialization tree keeps none of the indentation. | The Infoset keeps every text item, including the ones that are only line feeds and spaces. |
| Who strips it? | Your emitter, by choosing plain, quoted or block style. | Your application, by choosing whether to ignore element-content whitespace. |
Two answers to collisions
Namespaces against anchors
Every format that lets two people extend a vocabulary has to answer one question: what happens when both of them want to write the same key. XML answered in 1999. YAML never answered, and the ecosystem answered with anchors, which are a different mechanism solving a different problem.
XML: identity by URI, spelling by prefix
A namespace is an identifier that happens to be shaped like a URI, and the recommendation is emphatic that the resemblance is not an invitation: it is not a goal that the namespace name be directly usable for retrieval. Processors compare the string. Two declarations with the same URI put elements in the same namespace; two URIs differing by one trailing slash put them in different ones. The prefix is decoration, and the Infoset proves it by keeping namespace identity as a property of the element item rather than as a piece of the tag. Four rules do all the damage in practice:
<release xmlns="https://example.com/manifest/1"
xmlns:ops="https://example.com/ops/1">
<window unit="minutes">30</window>
<ops:window unit="minutes">30</ops:window>
</release>channel and unit are in no namespace at all, even with a default namespace declared on the root, because a default namespace applies to unprefixed element names and deliberately not to attribute names — the most misunderstood rule in XML, and the reason attribute-heavy formats look namespace-clean and are not. Meanwhile window and ops:window are different names: the first inherits https://example.com/manifest/1, the second is in ops. A declaration scopes its prefix from its start-tag to the matching end-tag and an inner declaration overrides an outer one, the xml prefix is bound by definition and x-m-l prefixes in any case are reserved, and a used prefix must be declared — while an undeclared default namespace is simply an ordinary document in no namespace.
Against collisions XML offers exactly three slots: a different namespace URI, an attribute rather than a child element, or a repeated element in a known position. That is a small but real vocabulary, and it is why XML Schema wildcards can say "anything from a namespace I have not heard of goes here" and mean it — Part 1 §3.10 lets a schema set processContents to strict, lax or skip for elements matching xs:any. YAML has no equivalent sentence, because it has no standard notion of a vocabulary attached to a key.
YAML: identity by anchor, extension by tag
YAML's answer to repetition is not namespacing but sharing, and it is the one place YAML is strictly more expressive than XML.
rollback: &rb
strategy: blue-green
window: 30m
services:
- name: api
rollback: *rb
- name: worker
rollback: *rb§3.3.1 makes one structural promise: every alias shall refer to a previous node identified by an anchor, and processors should reject ill-formed streams and unidentified aliases. Notice what it does not say — nothing about how many times an alias may be expanded, nothing about depth, and nothing about whether the loaded structure shares one object or copies it twice. That silence is why the same file is a memory-saving device in one loader and a hazard in another (see the security section). XML has no in-document reference that means "these two subtrees are the same node", so a converter expands this into copies.
For key collisions YAML gives two weaker tools. Tags (§6.9.1, §3.3.2-3.3.4) attach a URI to a node, so a vocabulary can be named — but it names the type of the node, not the namespace of the key, and §3.3.3 states the honest limit: for a node to be valid its tag must be recognized by the processor, which makes vendor extension a matter of whose parser you are running rather than of what your document says. The other tool is a naming convention — dotted keys, prefixed keys, a nested map under a vendor name — and none of those is checkable.
This is why the round trip earlier produced unreadable output when the writer invented a namespace per level, and it is the opposite mistake to the one a YAML author makes. In XML, prefix soup is visible and painful: three declarations, four generic item element names, every path broken, because the namespace name of rollback is now a function of where in the document it appears. In YAML the same situation looks fine: vendor-prefixed keys that no tool validates, collides or resolves. Choose the failure you can see — or decide the vocabulary once, at the root, and let converters inherit it.
Where the type lives
Type resolution against xsi:type
Here the two formats disagree most sharply, and not about whether they are typed. The disagreement is where the type is stored: in the text, or in a document somewhere else.
YAML decides from the characters. §10.1 defines a failsafe schema that resolves everything to sequences, mappings and strings; §10.2 a JSON schema; §10.3 the core schema, which the specification calls "the recommended default schema that YAML processor should use unless instructed otherwise". The core schema is a table of regular expressions applied to plain scalars. Its consequences are worth knowing exactly: a leading + is accepted as an integer, which JSON forbids; underscores are not accepted, though YAML 1.1 took them; and timestamps are not in the core schema at all — the 2001-12-14t21:59:43.10-05:00 form is a 1.1 type-repository convention documented in the YAML 1.1 timestamp type page, which is why the same date string is a date in one loader and a string in another.
XML decides from a schema, and says so out loud. Without a schema-informed processor XML is entirely text, and that is not a metaphor: Part 2 §3.2.1 defines string as finite sequences of characters matching the Char production, and §2.5.2 puts anySimpleType as the base of every primitive datatype, so all values reach the application as lexical strings that validation later constrains. The manifest says replicas is 3 in exactly the way a CSV file does — by you agreeing to read it that way. Type can be asserted per instance with xsi:type, which Part 1 §2.6.1 defines as an attribute whose value is a QName resolved to a type definition.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://example.com/manifest/1"
elementFormDefault="qualified">
<xs:element name="release" type="m:Release" xmlns:m="https://example.com/manifest/1"/>
<xs:complexType name="Release">
<xs:sequence>
<xs:element name="rollback" type="m:Rollback"/>
<xs:element name="services" type="m:Services"/>
<xs:element name="notes" type="m:Notes" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="id" type="xs:token" use="required"/>
<xs:attribute name="channel" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="stable"/>
<xs:enumeration value="canary"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:complexType name="Notes" mixed="true">
<xs:sequence><xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/></xs:sequence>
</xs:complexType>
</xs:schema>Four things this buys that no YAML file can buy by itself: the id is a token rather than a number, so 2026.42 stays a string; channel is an open enumeration, so a typo is a validation error rather than an unexpected deployment; Notes declares itself mixed, so a processor is obliged to tell you the whitespace there is content; and a type named Release can be reused and substituted for, under §3.3.6, which requires members of a substitution group to share, refine or extend the head's type definition.
# XML: type asserted on the instance
# <replicas xsi:type="xs:positiveInteger"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">3</replicas>
# YAML: the same claim made with an explicit tag
replicas: !!int 3
release_id: !!str 2026.42
window: !!str 30m
approved: !!bool false
built: !example,tag:yaml.org,2026:timestamp 2026-11-12T09:04:00ZThe XML assertion is checked by a processor against a published datatype definition; the YAML tag is checked against nothing unless your loader was configured to recognize it. §3.3.3 is blunt: to be valid, a node must have a tag recognized by the processor, so the !!int above is a request, and the last line is an application-specific tag most parsers will refuse to resolve at all.
| Written as | YAML core schema (§10.3) | XML Schema datatype | Note |
|---|---|---|---|
| 2026.42 | float 2026.42 | xs:string unless asserted | The YAML version is why release identifiers get quoted; 2026.40 would print as 2026.4. |
| +12 | int 12 | xs:integer accepts +12 | JSON forbids the leading plus, so this YAML is not JSON; see the JSON schema row in §10.2. |
| 0o14 | int 12 | not valid xs:integer lexical input | Base-8 and base-16 spellings exist only in YAML; in XML you would use xs:hexBinary or a custom type. |
| 1_000 | string (underscores are YAML 1.1) | not valid xs:integer | A YAML 1.1 loader reads int 1000; a 1.2 loader reads a string. Both are conformant. |
| yes | string in 1.2 core, bool in 1.1 | xs:boolean does not accept yes | Part 2 §3.2.2.1 allows only true, false, 1 and 0 as lexical values — the strictest of the three. |
| .inf | float positive infinity | xs:double accepts INF and -INF, xs:decimal does not | Decimal is exact (i times 10 to the minus n), so infinity is not in its value space at all. |
| .nan | float NaN | xs:double accepts NaN, xs:decimal does not | Neither format can round-trip NaN through JSON. |
| 2026-11-12 | string in core, date in 1.1 repositories | xs:date with optional time zone | The one type both ecosystems claim and neither agrees on without configuration. |
| null / ~ / empty | null | absent element or xsi:nil="true" | XML needs an explicit nil attribute plus a nillable declaration; YAML has a scalar. |
Read as a decision, the table says something uncomfortable about both formats: untyped input plus a guessing resolver is the same situation as typed input plus no schema, which is where most XML in production actually lives. The difference is that XML has a published way to fix it that every processor understands, and YAML has a published set of guesses and a third-party schema language bolted on afterwards.
Bytes
Verbose in what way, measured
XML is verbose. The interesting question is verbose in what currency, because the answer determines whether it costs you anything you care about. The recipe, so you can reproduce it: for XML every byte inside a start-tag, end-tag, the declaration, the comment and the processing instruction counts as markup, whitespace-only text between tags as whitespace, and the rest as payload; for YAML, indentation, line breaks, key text plus the following colon and space, the dash indicators, the comment, the directive and the two document markers count as structure, and scalar content as payload. Both partitions add up exactly to the file size, which is the property that makes them comparable.
| Measure | YAML | XML | Ratio |
|---|---|---|---|
| Whole file | 545 | 1,067 | 1.96 |
| Markup or structure | 334 | 739 | 2.21 |
| Whitespace-only text nodes | included above | 158 | 31 of 46 text segments |
| Payload | 211 | 170 | 0.81 |
| Structure per payload byte | 1.58 | 4.35 | XML spends 2.75 times as much per byte of content |
| Named things | 20 mapping keys, 2 block sequence entries, 1 flow sequence of 2 | 21 elements, 10 attributes, 2 namespace declarations | - |
| Gzipped at level 9, this file | 331 | 478 | 1.44 |
The payload row deserves a caveat the ratio does not: the XML version stores several values as attributes, which the recipe counts as markup, while the YAML version stores the equivalents as scalars, counted as payload. That is a fair reflection of what a parser does with them, not of which bytes carry information.
The interesting number is structure per byte of content: 4.35 for XML against 1.58 for YAML. But per-record repetition is what bandwidth is made of, so both documents were expanded into 200-record files — the release id incrementing, the replica count varying — and measured again.
| Encoding | Raw bytes | Gzipped | Compressed as a share of raw | Ratio to YAML |
|---|---|---|---|---|
| YAML multi-document stream | 100,226 | 2,291 | 2.29% | 1.00 |
| XML wrapper document | 209,738 | 3,211 | 1.53% | 1.40 |
| Difference | 109,512 | 920 | deflate favours XML | raw ratio 2.09 falls to 1.40 gzipped |
Measured here with Python’s gzip module at compression level 9 on the two generated files, which contain 200 copies of the manifest above with the release id and replica count varied per record. Parse time and memory were not benchmarked: those are the costs that do not show up in a size table, and they depend on library versions in ways that would need a test environment to state honestly.
Compression favours XML because XML verbosity is almost entirely repetition of a small alphabet of element names, and repetition at a distance is what a sliding-window compressor is for: 21 elements means 42 tag delimiters in which strategy and rollback recur endlessly, and 158 bytes of indentation compress to almost nothing. YAML's savings are distributed differently — the anchor and alias saved one repeated block in the source, which is a saving no compressor can make twice.
So verbosity has three prices. Bandwidth: about 40 per cent worse for XML on this corpus compressed, rarely a decision in 2026. Storage: roughly 2x, which matters at archive scale. Human cost: 1,067 bytes against 545 for the same document — 21 paired tags and 31 whitespace-only text nodes against 26 lines whose structure is 20 key colons and 2 dash indicators. The last of those is why people pick YAML for a file a human edits under time pressure, and it is a legitimate reason, provided they also accept that the file now has no standard way to say what it means.
Security
Two attack surfaces, both optional
This is the comparison most often stated wrongly, in both directions. Neither format is insecure by design; both ship an optional, powerful mechanism specified before adversarial input was a normal case, and both sets of advisories are about that mechanism being left on.
XML: DTDs, external entities, expansion
XML's extra machinery is the document type declaration and the entity mechanism built on it, productions [26]-[28], [68]-[77] and §4.3. External general and parameter entities let a document name a resource the processor should substitute — file disclosure, server-side request forgery and port scanning when that resource is file:///etc/passwd or an internal endpoint, in what the industry calls XXE. Entity expansion turns the substitution rules into a multiplier: a handful of nested definitions produce an exponentially larger tree, the billion laughs pattern, which the specification addresses only through the recursion constraint in §4.3.2 — a parsed entity MUST NOT contain a recursive reference to itself, directly or indirectly. Non-recursive nesting is not recursion, so the rule stops nothing relevant.
<?xml version="1.0"?>
<!DOCTYPE r [
<!ENTITY x SYSTEM "file:///etc/passwd">
<!-- disclosure: &x; in element content -->
<!-- SSRF: <!ENTITY y SYSTEM "http://169.254.169.254/latest/meta-data/"> -->
<!ENTITY a "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa">
<!ENTITY b "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;">
<!ENTITY c "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
<!-- each level multiplies by 16; seven levels is roughly 800 MB of text
expanded from a file of a few hundred bytes -->
]>
<r>&x;</r>Illustrative, truncated deliberately at three expansion levels. The mechanism is textual substitution before parsing completes, which is why the resulting tree can be far larger than the bytes on the wire — and why a processor cannot detect it from the document size alone.
The published mitigations reduce to one instruction. The OWASP XXE guidance entry in this page's sources says a processor should use a local static DTD and disallow any DTD declared in the document; in practice that means turning DTD processing off entirely, and where that is impossible, disabling external-entity resolution and capping expansion. The consequences are not theoretical: CVE-2019-5427 is a billion-laughs exposure in c3p0 before 0.9.5.4 caused by loading XML configuration without recursive-expansion protection, and CVE-2021-32623 is the same class in Opencast before 9.6. Note the common shape: in both cases the XML was the configuration, and the parser feature was never disabled because the configuration was trusted.
YAML: tags, and aliases with no budget
YAML has nothing like a DTD: no external entities, no parameter entities, no notations, no unparsed entities and no substitution step at all, so the entire XXE class is unavailable and the billion-laughs construction has no lexical form. What it has is two features that arrive at the same place by a different route.
The first is tags. §3.3.2 states plainly that tag resolution is specific to the application and that processors should provide a mechanism for the application to override and expand the default rules. That is a sound design decision and also the door: a resolver that maps a tag to a constructor can be persuaded to build an object, and object construction is code execution. The history is documented — PyYAML’s yaml.load() executing arbitrary code on untrusted data before 5.1 (CVE-2017-18342, followed by CVE-2020-14343 against the partial fix) is exactly this mechanism — and loaders restricted to the core schema, including most modern JavaScript and Go implementations, are not vulnerable because they have no constructor registry to abuse.
The second is aliases, and this is the surprise: YAML's answer to entity expansion is structurally identical to the problem. An alias means the same node again, and if a loader expands it at load time instead of sharing the object, expansion multiplies with nothing in the specification to bound it — §3.3.1 requires only that each alias refer to a previously anchored node. CVE-2023-47163 records Remarshal before 0.17.1 expanding YAML alias nodes without limit, described in the advisory as a billion-laughs attack against YAML, and CVE-2022-25857 covers SnakeYAML before 1.31 lacking a nested-depth limitation for collections.
a: &a ["x","x","x","x","x","x","x","x","x","x","x","x","x","x","x","x"]
b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a,*a]
c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b,*b]
d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c,*c]
e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d,*d]Sixteen aliases per level, five levels: 16 to the power 5, about one million leaf references, from 295 bytes of text. If the loader shares nodes this is a graph of a million references and a small tree; if it deep-copies, it is a memory-exhaustion bug in whatever language the loader happens to be written in. The file is entirely well-formed by §3.3.1, and no clause caps the work.
| Class | XML mechanism | YAML mechanism | Setting that removes it |
|---|---|---|---|
| File disclosure | External general entity with a system identifier | None — there is no substitution step | Disallow DTDs |
| Server-side request forgery | External entity pointing at a URL | None | Disallow DTDs, disable resolver |
| Expansion DoS | Nested internal entities, each level multiplying | Alias fan-out, expanding at load | Cap expansions; cap alias work |
| Depth DoS | Deeply nested elements (parser stack) | Deeply nested flow collections | Depth limits, e.g. SnakeYAML 1.31 |
| Object construction | Not a format feature; bound to schema-driven binding tools | Tag resolution to a constructor | Restrict to the core schema, no custom resolvers |
| Grammar abuse | DTD defaults surprising a schemaless reader | Not applicable — YAML has no defaults | Validate against a schema, do not rely on defaults |
| Encoding confusion | Declaration versus byte-order mark (RFC 7303 is explicit) | UTF-8, UTF-16 by BOM only (§5.2) | Require UTF-8, reject BOM surprises |
The final column is the only genuine difference in kind: the XML rows are switched off by refusing to process a feature that is genuinely optional, and the YAML rows by bounding work and narrowing a resolver. Neither format can be made safe by its own text.
Twenty-five years of implementations
The toolchain gap: validators, paths, transforms
Format arguments are usually settled by ecosystem, and here the asymmetry is the whole story. XML ships with a validation and transformation stack specified in public documents and implemented many times over since 1998: constraint checking with DTDs, XML Schema 1.0 and 1.1, RELAX NG and Schematron; addressing with XPath and XPointer; transformation with XSLT; canonical serialisation with Canonical XML and Exclusive XML Canonicalisation; signing with XMLDSig; type mapping with Schema Part 2's built-in datatype library. Each has independent implementations that a conformance clause forces to agree. YAML has a syntax specification, three recommended tag schemas, and then libraries: validation is JSON Schema or a language-specific type system, querying is yq in at least three unrelated dialects that share a name, transformation is code, and canonical form does not exist — which is why signing YAML in practice means converting it to JSON first.
# 1. Validate the document against a published contract
xmllint --schema manifest.xsd --noout manifest.xml # one tool, one grammar language
# YAML has no equivalent single step:
yq eval '.' manifest.yaml # syntax only
check-jsonschema --schemafile manifest.schema.json converted.json
# 2. Address a node
xmllint --xpath 'string(//m:service[@kind="api"]/m:image)' manifest.xml
yq '.services.service[] | select(._kind == "api") | .image' manifest.yaml # jq-flavoured
# 3. Transform, and prove the result is the same tree
xsltproc normalise.xsl manifest.xml > canonical.xml
java -jar xmlsec1.jar canonicalize canonical.xml > digest.xml
# YAML: re-emit with your emitter and diff; there is no canonicaliser to disagree withThe shape of the workflow is the argument, not the tools: XML validation and transformation are separate programs with a documented interface between them, so the contract outlives the project that wrote it. The YAML workflow has a syntax checker in step one and a schema chosen by whoever set up the pipeline, which means a wrong schema and a missing schema look identical from the command line.
What a compiler-quality validator buys a config format is the strongest single argument for XML, and it is rarely articulated. Error localisation about the contract rather than the bytes — that the value of attribute channel in element release at line 3 is not one of the allowed enumeration values, which is a sentence a reviewer can act on. Machine-checkable contracts between organisations, so a vendor can be told "conform to this file" and tested against it. Type assignment before application code runs, which removes a class of coercion bugs downstream. Reuse, through named complex types, substitution groups and wildcards with documented processing modes. Determinism across implementations, which is what a conformance clause is for.
What it costs is real, and YAML authors are not wrong to resent it. XSD is a type system with subset rules and validity constraints of its own prose; Part 1 defines a family of "must" and "shall" obligations on schema documents that nobody reads twice, tooling is heavy, error messages are famously verbose, and the expressive ceiling is lower than people expect — XSD cannot say "exactly one of these two elements, and I will tell you which one you got" without contortions, which is why Schematron exists alongside it. Most damaging for config: a schema is a second artefact to version, publish and migrate, and the gap between the schema and the loader's behaviour is where outages live.
The honest position is that YAML does not lack validation because its designers were careless; it lacks it because permissive tag resolution (§3.3.2) does not compose with a normative constraint language. Want machine-checkable YAML without XML and you end up with JSON Schema plus a convention that everything passes through a typed boundary — two documents and a discipline instead of one schema.
Migration
Migrating XML to YAML: a failure catalogue
This section is ordered by how long each failure takes to notice, which is roughly the reverse of how often it is discussed.
1. The contract disappears. The day you stop shipping a schema, the document stops being checkable by anyone who is not your code. Mitigation is a JSON Schema plus typed parsing plus a lint stage, and it must exist before the migration, not after the first outage; the Config Conversion workflow page covers the practical order.
2. Scalars change type. The round trip in the second section emitted _text: yes unquoted, and a 1.1 loader resolves that to boolean true: a feature flag becomes a different type because of a conversion step nobody reviewed. The whole class — yes, no, on, off, the country code NO, the version 1.10 becoming 1.1, the identifier 0o755 becoming 493 — comes from the resolver tables in §10 and is documented in the YAML guide. The rule is mechanical: quote any scalar that is not a number you intend to do arithmetic with.
3. Attribute flattening collides. Eleven synthetic keys in the measured round trip, and the collisions stay invisible until two of them land on the same key name. Choose a documented convention once, per converter, and reject documents that would violate it — the alternative is silent data loss, which happened here to nothing at all only because the example was small.
4. Mixed content is destroyed. If your XML has prose in the middle of structure — and if it came from DocBook, DITA, a SAML message with human-readable text, an SVG label or an Office document, it does — YAML cannot hold it. That is not a converter defect. It is the correct conclusion that the artefact is a document, and the migration should stop.
5. Anchors become copies. Expansion loses the identity claim, and the second-order problem bites later: after a load, a shared aliased node means an edit at one position is visible at the other, while a deep-copied one means the two drift. A tool that round-trips YAML without tracking anchors silently changes which of those worlds you live in, and a merge key (<<, a 1.1 convention rather than a core-schema feature) makes it worse, because inherited keys look native.
6. Namespaces are re-invented badly. The per-level namespace soup is the case above; the subtler failure is dropping namespace identity entirely, because two vocabularies that coexisted peacefully in XML become one key namespace in YAML, and a type attribute from each provider now overwrites the other.
7. Ordering assumptions survive by luck. YAML mapping keys are unordered by definition; if the old XML relied on document order among siblings — batch steps, filter chains, security policy assertions — the sequence must become an explicit sequence, not a mapping.
8. Pointing and signing do not migrate. XPointer and XPath-based fragment addressing have no YAML counterpart, and XMLDSig depends on canonicalisation, which YAML does not have. A signed payload is not a config file; leave it where it is.
9. The encoding declaration disappears. RFC 7303 gives XML a per-document story: the byte-order mark is authoritative, the declaration states the encoding, and application/xml versus text/xml carries rules. YAML streams are UTF-8, UTF-16BE or UTF-16LE, detected by the BOM (§5.2), with nothing inside the document to declare. When the transport lies about the charset, XML has a second channel to correct it and YAML does not.
Decide
Fidelity matrix, decision table and what this site converts
Two tables finish the argument. The first is what a converter can promise, feature by feature; read its middle column as "instructions you must write down somewhere". The second is the choice itself, stated as a question about contracts.
| Feature in the source | Direction | Fidelity | What the converter must be told |
|---|---|---|---|
| Nested mappings and sequences | both ways | lossless | Nothing — this is the common subset both models share. |
| Scalar text | both ways | lossless, types not | Whether to quote; and the target loader’s schema version. |
| Attributes | XML to YAML | recoverable only by convention | A key prefix, and a rule for attribute-versus-child collisions. |
| Namespaces | XML to YAML | identity can be kept, prefix scope cannot | Whether to expand URIs into keys, keep them as metadata, or resolve them once. |
| Mixed content | XML to YAML | lossy | Nothing helps; the artefact is a document. |
| Comments | both ways | usually dropped | Whether the emitter preserves comments, which most do not. |
| Processing instructions | XML to anything | lost | Treated as markup nobody recognises. |
| DTD or schema references | XML to YAML | lost | This is where the contract went; you need to re-create it elsewhere. |
| Anchors and aliases | YAML to XML | lost, expanded to duplicates | Whether the identity was semantic or a typing convenience. |
| Explicit tags | YAML to XML | usually demoted to an attribute | Which tags map to xsi:type assertions and which are dropped. |
| Explicit keys | YAML to XML | lost | A naming scheme for structure-valued keys, or a refusal. |
| Block scalars | YAML to XML | text survives, intent does not | Whether to emit xml:space, and how trailing newlines are decided. |
| Multi-document streams | YAML to XML | shape changes | A wrapper element name, which invalidates existing paths. |
| Merge keys | YAML to XML | invisible | Whether inherited keys should be marked, and nothing can mark them. |
| Document order | YAML to XML | assumed | That a mapping order is not load-bearing; if it is, fix the YAML first. |
| Situation | Choose | Because |
|---|---|---|
| Config read only by your own services | YAML | Less markup per byte, better for human edits, and you can supply the discipline the format lacks. |
| Config consumed by third parties you do not control | XML plus a published schema, or JSON plus JSON Schema | A contract an outsider can test without your source. |
| Prose, documentation, authoring | XML | Mixed content, stylesheets and DITA or DocBook tooling already exist. |
| Payloads that must be signed or encrypted | XML | Canonicalisation is specified; there is no YAML equivalent. |
| Data with a schema and no structure | CSV or JSON | If your XML is only flat records, you are paying for a markup language. |
| Kubernetes, CI and deployment manifests | YAML | The ecosystem, the diffing tools and the templating all assume it. |
| Wire formats specified in the 2000s | XML | SOAP, SAML, Office Open XML and SVG are XML; conversion is a rewrite. |
| Anything whose types matter | either, with a schema | Untyped YAML and unvalidated XML have the same hole, and only one has a standard filler. |
- Common subset
- Mappings, sequences and strings. Everything outside it is a convention you must specify yourself.
- Fidelity
- Whether the result re-expresses the same claim, not whether the same characters survive.
- Converter rule
- A written decision about attributes, namespaces and mixed content. Every XML-to-YAML tool has them; almost none publish them.
- Schema discipline
- For YAML: a JSON Schema, typed parsing at the boundary and a lint stage. Without it, YAML has no contract at all.
What this site converts, and what it does not
Be clear about the tooling position, because it is a deliberate limit. FmtTools runs entirely in the browser and handles JSON, YAML, CSV, TSV, NDJSON and Base64. It has a YAML-to-JSON converter and a JSON-to-YAML converter, and it has no XML parser, no XSD or RELAX NG validator, and no XML-to-YAML or YAML-to-XML converter. That is not an oversight: as the fidelity matrix shows, an XML converter is a set of policy decisions about attributes, namespaces and mixed content before it is a program, and a page that silently picked those defaults would be making a vocabulary decision on your behalf.
What the tools here are genuinely good for in an XML-to-YAML migration is the inspection step. When a converter hands you JSON — from xml2js, xmllint --xpath piped through a script, or your own XSLT — paste the result into JSON to YAML to see what the emitter would do to your scalars, and paste the YAML back into YAML to JSON to see what a resolver decided about types. That is where the yes-becomes-boolean and 2026.42-becomes-float defects appear, and they appear faster in a browser than in a pipeline. For the XML side of the boundary you still need xmllint, yq or an XSLT stylesheet, and none of those live here.
The verdict, in the form I would put in front of the punctuation arguments: YAML and XML differ most in what their standards bodies agreed to specify. XML standardised the tree, the constraints, the addressing and the canonical form, then left the syntax ugly. YAML standardised a beautiful syntax for a graph, then left everything above it to your configuration. Pick according to which half of that you can afford to own.
Answers
Questions about YAML and XML
Is YAML or XML the better format for configuration in 2026?
YAML is better when every reader of the file is code you control, because then a schema language, a path syntax and a canonical form are things you may decline to have. XML is better when a party you do not control parses the file: XML Schema, XPath and XSLT are normative, so a vendor, a regulator or an open-source consumer can check your document against a published contract instead of against your parser configuration. Most teams choosing between the two are choosing who validates the file.
Why does XML have a standard schema language and YAML does not?
XML needed one to be a markup metalanguage: without a grammar language there is no way to say what a vocabulary allows, and the 1998 design put that job in the DTD. XML Schema (2001) replaced DTDs with a type system over the Infoset. YAML has nothing equivalent because its specification defines tag resolution over scalar text instead: the core schema in YAML 1.2.2 section 10.3 is a set of regular expressions, and validation of structure is delegated to third-party languages such as JSON Schema.
Can I convert XML to YAML without losing data?
No, unless you accept an invented encoding. Attributes, namespace declarations, mixed content, processing instructions, comments and DTD declarations have no slots in the YAML representation graph, so a converter must either drop them or invent keys for them. The document in this article grew from 545 bytes of YAML to 856 bytes of round-tripped YAML because eleven synthetic keys were invented and one alias was expanded into a duplicate. Data survives; the encoding of the intent usually does not.
Which format is more dangerous to parse?
Both are dangerous through optional parser features rather than through their core syntax. XML exposes external entities, which gives file disclosure, server-side request forgery and entity-expansion denial of service; disabling DTD processing removes all three. YAML exposes tag-based construction and unbounded alias expansion, which give code execution in some loaders and memory exhaustion in most; restricting the schema and capping alias work removes both. If you can only change one setting, turn off DTDs and resolve only the core schema.
Does compression make the size difference disappear?
Mostly. The 200-record corpus measured here is 100,226 bytes as YAML and 209,738 as XML, a raw ratio of 2.09, and 2,291 against 3,211 bytes gzipped at level 9, a ratio of 1.40. XML verbosity is mostly repetition of element names, and repetition is exactly what deflate monetises. What compression does not fix is the per-node memory cost of an XML tree or the number of characters a human must type and read.
Why does my XPath stop matching after a namespace change?
Because an unprefixed element name in a document with a default namespace is not in the empty namespace. XPath 3.1 matches a step against a namespace name plus a local name, so //service asks for an element with no namespace, and finds nothing in a document whose services inherit https://example.com/manifest/1. Bind a prefix in your evaluator or match on local-name(). The same trap appears when a YAML-to-XML writer invents a namespace per nesting level: the path worked before the conversion only by accident.
What happens to YAML anchors when they are converted to XML?
They are expanded, because XML has no in-document reference that means "this subtree is the same node as that one". General entities come close but substitute text before the tree is built, and XLink is an attribute vocabulary rather than identity. So the alias disappears, the repeated block is duplicated, and an edit that used to change one place in the file now has to be made in every copy. If the alias encoded a deliberate shared identity, that fact is lost silently.
Can this site convert XML to YAML?
No. FmtTools parses and rewrites JSON, YAML, CSV, TSV, NDJSON and Base64 in the browser, and has no XML parser, no XSD or RELAX NG validator and no XML-to-YAML converter, because a correct one would have to decide the namespace, attribute and mixed-content rules first. What the site does have is the YAML-to-JSON and JSON-to-YAML pair, which is the practical way to inspect the JSON an external converter produced.
Related
Next up
Sources and further reading
- [1]XML 1.0 (Fifth Edition) — W3C Recommendation, 26 November 2008 — Checked for: the definition of a well-formed document in 2.1 and the document production [1]; the section numbering and productions for Comments [15], Processing Instructions [16], CDATA [18]-[21], prolog [22]-[27] and the document type declaration [28]; White Space Handling in 2.10, including the MUST sentence that a validating processor informs the application which characters constitute white space appearing in element content and the sentence introducing the special attribute xml:space; attribute-value normalisation in 3.3.3; the no-recursion rule that a parsed entity MUST NOT contain a recursive reference to itself, directly or indirectly, in 4.3.2; and the validity definition in 3.4. (accessed November 12, 2026)
- [2]XML Information Set (Second Edition) — W3C Recommendation, 4 February 2004 — Checked for: the statement that the XML Information Set is an abstract data model for XML documents rather than a physical one; the eleven kinds of information item (document, element, attribute, namespace, text, processing instruction, comment, document type declaration, entity reference, notation and unparsed entity); the [namespace name] property of an element item and the single [normalized value] property of an attribute item; that text items carry character data; and the exclusions around attribute values supplied by DTD defaults. (accessed November 12, 2026)
- [3]XML Schema Part 1: Structures (Second Edition) — W3C Recommendation, 28 October 2004 — Checked for: 2.2, which says that building on the information set gives a priori guarantees of well-formedness and namespace conformance; 2.6.1, where the type assertion attribute is defined and its value stated to be a QName interpreted through 3.15.3; 3.2.1 on the default and fixed attribute use terms; 3.3.6 on type substitution requiring members to share or refine the head type definition; and 3.10 on processContents taking strict, lax and skip for wildcard matches. (accessed November 12, 2026)
- [4]XML Schema Part 2: Datatypes (Second Edition) — W3C Recommendation, 28 October 2004 — Checked for: 3.2.1 defining string as finite sequences of characters matching the Char production; 3.2.2.1 listing the boolean lexical literals true, false, 1 and 0 against the value space true and false; 3.2.3 defining decimal as i times 10 to the minus n; 3.2.4.1 and 3.2.5.1 giving the float and double lexical forms including INF, -INF and NaN; 3.2.9.1 giving the date lexical form; 2.5.2 establishing anySimpleType as the base of all primitive datatypes; and the canonical representation rules used in the type tables here. (accessed November 12, 2026)
- [5]XPath 3.1 — W3C Recommendation — Checked for: the path syntax that makes element and attribute addressing a standardised operation on an XML document, the axes and node tests used in the examples here, and the requirement that a bare name test in a path matches the namespace name plus local name — the reason a default namespace breaks an otherwise obvious expression. (accessed November 12, 2026)
- [6]YAML Ain’t Markup Language (YAML) Specification Revision 1.2.2 — Checked for: 3.2.1, which describes the representation as a rooted, connected, directed graph of tagged nodes that may include cycles and nodes with more than one incoming edge, and 3.2.2 and 3.2.3 for the serialization tree and presentation stream; 3.3.1 requiring each alias to refer to a previously anchored node; 3.3.2 stating that tag resolution is specific to the application and that processors should let it be overridden; 3.3.3 on recognized and valid tags; 5.3 productions [4]-[6] and [15]-[17]; 6.1 including the rule that tab characters must not be used in indentation and that the amount of indentation is a presentation detail; 6.2 separation spaces; 8.1 block scalars with indentation and chomping indicators; 9.1 and 9.2 documents and streams; and the 10.2 JSON and 10.3 core schema resolution tables. (accessed November 12, 2026)
- [7]RFC 7303 — XML Media Types — Checked for: the registration of application/xml and text/xml, the rule that they may not be used unless the parsed entities are also well-formed document entities, the authority of the byte-order mark for the encoding and the UTF-8 default, and the security considerations naming external DTDs and entities. Also consulted: RFC 9512, which registers application/yaml and points at YAML 1.2. (accessed November 12, 2026)
- [8]OWASP — XML External Entity (XXE) Processing — Checked for the recommended posture that an XML processor be configured to use a local static DTD and disallow any declared DTD included in the XML document, which is the mitigation the security table in this article is organised around, and for the classification of entity expansion as a distinct denial-of-service consequence rather than a disclosure one. (accessed November 12, 2026)
