Converters

YAML to XML Converter

Convert YAML into well-formed XML, with explicit handling for the single-root rule and for keys XML cannot name.

Private by design — your data never leaves your device.
✓ Free forever✓ No sign-up✓ No ads✓ Works offline once loaded

YAML to XML Converter

Convert YAML into well-formed XML, with explicit handling for the single-root rule and for keys XML cannot name.

Input

Your YAML

Nothing is uploaded.

Output

XML output

Your result appears herePaste on the left and select “Convert to XML”

Converting YAML to XML is the direction people take when a modern config has to feed an older consumer: an enterprise integration bus that only accepts XML, a SOAP endpoint, a reporting tool built around XSLT, or a Java application whose configuration loader predates the YAML era. The data is already in the shape you want; it is the notation that has to change.

Two structural mismatches decide the output. XML permits exactly one root element, while a YAML mapping can have any number of top-level keys and a YAML stream can hold several documents. And XML element names are constrained — they cannot begin with a digit or contain spaces — while YAML keys can be almost anything, including numbers and booleans. Both are handled explicitly and described below. Everything runs in your browser in a Web Worker.

How it works

How to use the yaml to xml

  1. 1

    Paste your YAML

    A workflow, a Compose file, a values file, a playbook. Anchors and aliases are resolved during parsing; comments are dropped, since XML comments cannot be inferred from them.

  2. 2

    Choose indentation for the XML

    Two or four spaces, or tabs. An XML declaration is always emitted at the top of the output.

  3. 3

    Check the root element and element names

    A note tells you if a synthetic <root> wrapper was added. Scan for element names containing underscores, which indicate a YAML key that was not a legal XML name.

How your YAML is reshaped

The YAML is parsed into a data model and that model is serialised as XML. The rules that matter:

  • One top-level key becomes the root element. A YAML file whose entire content sits under a single key converts to XML with that key as the root and no artificial wrapper. This gives the cleanest output, so it is worth restructuring for.
  • Several top-level keys are wrapped in <root>. The workflow file in the example has name, on, env and jobs at the top level, so all four become children of a synthetic root. XML has no way to express four peers at the document level.
  • Sequences become repeated elements. A list under steps: becomes several <steps> elements side by side, which is the conventional XML idiom for a collection. There is no <steps><step/></steps> wrapper unless your YAML already nests that way.
  • Scalars become text content. Numbers, booleans and dates all become their text representation, because XML text is untyped. enabled: true becomes <enabled>true</enabled>, and a consumer has to know from a schema that it should be read as a boolean.
  • Null becomes an empty element. A YAML key with no value, or an explicit ~, produces <key/>. The difference between null and the empty string is not preserved.
  • A key beginning with @ becomes an attribute and a key named #text becomes element text. That is the convention the XML to YAML tool emits, so the pair round-trips.
  • Reserved characters are escaped. Ampersands and angle brackets in your values are converted to entities automatically; you never need to pre-escape.

Keys that XML cannot name

XML element names must start with a letter or underscore and may then contain letters, digits, hyphens, full stops, underscores and colons. YAML keys have no such restriction, and real config files break the rules constantly.

Any key that is not a valid name is repaired: it gets an underscore prefix if needed, and each remaining illegal character is replaced with an underscore. timeout minutes becomes <timeout_minutes>, and a numeric key such as 2024 becomes <_2024>. Numeric keys are common in YAML — port maps, year-indexed data, HTTP status code tables — so expect to see this.

Two caveats. First, sanitisation can collide: on push and on-push both become on_push, and nothing warns you. Second, a key that YAML parsed as a boolean is stringified before it becomes an element name, which is why the GitHub Actions on: key is worth watching — under a YAML 1.1 parser it would have become the boolean true, though the YAML 1.2 parser used here keeps it as the string on.

If element names are contractual — because a schema or an XSLT stylesheet depends on them — check every name in the output rather than assuming the mapping was clean.

What is lost on the way through

Comments disappear. YAML comments carry no structural information and there is nothing in the data model to hold them, so they cannot be re-emitted as XML comments. Copy any that matter across by hand.

Anchors and aliases are expanded, not preserved. A block defined once with &defaults and referenced three times appears three times in full in the XML. The data is right and the file is bigger.

A multi-document stream is flattened. Because a stream parses to a list of documents and XML wants a single root, several documents end up as repeated child elements inside the synthetic root rather than as separate XML documents. If you need one XML document per YAML document, split the stream before converting.

No namespaces are generated. If the consuming system needs them, add an "@xmlns" key to the mapping that becomes your root before converting, and it will be emitted as a declaration on the root element. Likewise, the output will not validate against any particular XSD without deliberate shaping — well-formed is not the same as valid.

Common questions

YAML to XML FAQ

Why is there a <root> element I did not ask for?

Your YAML had more than one top-level key, or was a sequence, and XML allows exactly one root element. Nest everything under a single key in the YAML if you want to control the root name.

How do I make a value into an XML attribute?

Name the key with a leading @ in your YAML — "@id": 7 — and it is emitted as id="7" on the enclosing element. A #text key supplies the element's text content alongside it.

What happens to my comments and anchors?

Comments are dropped, and anchors are expanded so each reference becomes a full copy. Both are YAML authoring features with no XML equivalent that a converter could infer.

Will the XML validate against my schema?

Not automatically. This produces well-formed XML that mirrors your YAML structure. Matching an XSD requires specific element names, ordering, cardinality and namespaces, which means shaping the YAML deliberately or transforming the output afterwards.

Are numbers and booleans typed in the output?

No. XML text content has no type, so replicas: 4 becomes the text 4. Typing comes from a schema on the consuming side, not from the document itself.