Convert XML to YAML

Converting XML to YAML replaces closing tags with indentation, which typically halves the length of a config file and makes it readable in one screen. Attributes arrive as keys beginning with @ and element text under a key called #text, so nothing is lost — but the reason to do it is legibility, and the file is usually a view rather than a replacement.

  • Where it runs In your browser. The file is never uploaded.
  • Rebuilt YAML works differently from an XML, so this is not the gradual degradation a lossy codec applies. What YAML can express is reproduced faithfully; what it has no equivalent for does not survive at all.
  • File size limit Up to 100 MB per file, free, without an account.
  • Worth knowing XML attributes and text nodes both become keys, which is a judgement call the converter makes for you.

Up to 100 files at once. Mixed formats are fine.

What a pom.xml looks like once the closing tags are gone

XML spends roughly half its characters saying where an element ends. YAML says it with indentation, so the same document comes out substantially shorter and each nesting level is one visual step rather than a matched pair to scan for. On a Maven pom or a web.config that is the difference between scrolling and reading.

The structure is unchanged. Every element becomes a key, its children become the mapping beneath it, and text becomes the value. Nothing is reordered and nothing is summarised, so what you are looking at is the same document with the punctuation removed — which is exactly what you want when the purpose is to understand what the file says.

The keys that arrive in quotes, and why they must

Attributes come across as keys prefixed with @, and an element that carries both attributes and text stores that text under the key #text. Both get written with quotes around them, because YAML treats @ as a reserved indicator at the start of a plain scalar and # as the start of a comment.

It looks like noise and it is correctness. If you edit the file by hand, keep those quotes: removing them produces YAML that either fails to parse or, in the case of #text, silently turns the rest of the line into a comment and loses the value. The same applies if you retype a key while reshaping the output into a values file.

Using the YAML to diff two versions of a config

This is the strongest reason to make the conversion. Diffing XML is miserable because a change one level deep shows as several lines of tags, and reformatting by a tool rewrites the whole file. Converting both versions and diffing the YAML shows the changed values on their own lines with their key path visible above them.

One caveat makes or breaks it. Because a single repeated element becomes a mapping and two become a list, a version that added a second dependency changes the shape of that branch and not just its contents, so the diff shows the whole block as rewritten. That is not the converter losing information — it is the shape genuinely changing — but knowing it in advance saves you from reading a large diff as a large change.

Namespace prefixes, and the colon inside a key

Prefixes are preserved as part of the key name, so a document using soap: or xsi: produces keys containing a colon. The writer emits those unquoted, and they read back correctly through the same parser. The namespace declarations themselves survive as attributes, so a default xmlns arrives as a quoted "@xmlns" key on the root.

A colon inside an unquoted key is the kind of thing worth tightening by hand before the file travels. If the YAML is going to be read by another tool, quote those keys yourself — it costs nothing and removes a class of problem that only appears at the point where somebody else parses the file. Nothing resolves prefixes to their namespace URIs, so two documents using different prefixes for the same namespace produce YAML that does not diff cleanly against each other.

What stays a string and what quietly becomes a number

Values that read as numbers are parsed, in element text and in attributes alike. A Maven version of 4.13.2 stays a string, because it has two dots and cannot be a number, and so does an address or a path. A version attribute written 1.0 becomes 1, and a zero-padded value written 007 becomes 7.

On a config that is read rather than executed the damage is limited to how the value looks, and it still matters: a schema version rendered as 1 instead of 1.0 in a review is a value somebody will question or, worse, copy. Scan the numeric-looking values in the output once. If the YAML is going anywhere except a human eye, quote the ones that were meant as identifiers.

Long values, multi-line text and empty elements

A value containing newlines is written as a block scalar — a pipe character with the text indented beneath it — which keeps it readable rather than escaping it onto one line. A long single-line value is written as-is without wrapping. Both are the right choices for a file meant to be read.

An empty or self-closing element becomes an empty string, written as a pair of quotes. XML does not distinguish an empty element from one containing nothing, so no information is lost, but an empty string is visually easy to miss in a long file — if you are auditing a config for unset values, search for the empty quotes rather than trusting the eye.

The comments this conversion destroys

XML supports comments, YAML supports comments, and none of yours survive. The parser discards them and nothing writes them back. On a payload that is irrelevant; on a build file it is the single largest loss, because the comment above a pinned dependency version is usually the only surviving record of why it is pinned.

The working arrangement that avoids the trap is to treat the YAML as a reading copy and keep the XML as the source. If the YAML is instead going to become the source — a genuine migration into Ansible or a Helm chart — schedule the pass that copies the comments across as part of the work, before the XML is deleted and the reasoning is gone with it.

Reshaping the output into something a tool will accept

A converted config is not yet a values file or a variable set. It carries XML artefacts — the @ keys, the #text keys, a namespace declaration on the root, and possibly a ?xml key from the declaration line — which are meaningless to whatever you are feeding. Deleting them is the first pass.

The second is naming. XML element names are often verbose in ways that made sense with a schema behind them, and a YAML config usually wants them shorter and flatter. Both passes are manual and both are the actual migration; the conversion just gets you a legible starting point instead of a wall of tags.

When to convert and when to leave the XML alone

Convert when the goal is to understand, review or compare: the YAML is shorter, the structure is obvious, and the whole thing runs in your browser in the time it takes to drop the file. It is a good habit for any config file you have been handed and have to reason about before changing.

Do not convert when the file is validated by a schema, signed, or consumed by a tool that reads XML. The XML is the artefact in that case, and a YAML copy is a second version of the truth that will drift from the first. Read it as YAML, change it as XML.

How to convert XML to YAML

  1. Drop your XML file onto this page, or click to choose one.
  2. It is converted to YAML in your browser.
  3. Download or read the YAML, and keep the XML as the source.

XML against YAML: tags traded for indentation

XML compared with YAML
XMLYAML
Full nameExtensible Markup LanguageYAML Ain't Markup Language
File extension.xml.yaml, .yml
Media typeapplication/xmlapplication/yaml
First published19982001
Published byW3C
SpecificationXML 1.0YAML 1.2
LicensingOpen standardOpen standard
Standing todayCurrentCurrent
Opens in a browserEvery browserNo browser
Considered insteadJSONJSON, TOML

What survives

Comments carry across. Both XML and YAML have a comment syntax, so notes left for whoever maintains the file next are not silently thrown away.

Opening the result

No browser reads YAML. It is the less portable of the two, so it is worth being sure the program at the other end accepts it before sending one.

Visual Studio Code reads both XML and YAML, so there is a way to check the result against the original without a second tool.

What each format is for

XML is W3C's format, published in 1998. The specification is XML 1.0, and it is worth reading if the file has to outlive the tool that wrote it.

YAML dates from 2001, specified as YAML 1.2. Visual Studio Code and yq all read it.

XML to YAML: questions from a config review

Are my XML files uploaded anywhere?

No. This conversion runs entirely inside your browser, so the file never leaves your device. You can confirm it yourself: open the network tab of your browser's developer tools and convert something. You will see the page load, plus the analytics and advertising the site is paid for with — and nothing carrying your file.

Why are some keys in quotes?

Because YAML reserves those characters. An attribute arrives as a key beginning with @ and an element own text as a key named #text, and both have to be quoted — @ is a reserved indicator and # would start a comment. The quotes are part of correct YAML, not decoration.

Does the YAML keep the order of the XML?

Yes. Elements appear in the order they were written, and attributes appear after the child elements of the same tag. Nothing is sorted, which is what makes the output usable for a diff.

What happens to namespace prefixes?

They stay in the key name, so soap:Body becomes a key with a colon in it, written without quotes. It reads back correctly here; quote those keys by hand before handing the file to another tool if you want to be certain.

Why does one file have a list where another has a single value?

Because repetition in XML is data, not schema. One dependency element becomes a single mapping and two become a list, so the same document with one entry and with two produces different YAML. That is the thing to watch when diffing.

Are comments carried over?

No. XML comments are dropped while parsing and nothing writes them back, even though YAML supports comments. On a build file that is often the most valuable text in it, so keep the XML.

Does the file leave my machine?

No. Both halves run in this page as JavaScript, so a config with connection strings or licence keys in it stays local. Files up to 100 MB are accepted free.

More about these formats