Format Code Now
/

XML to YAML Converter

CV-114

Paste XML and get YAML. The root element is the top key, attributes start with @, and repeated elements become lists.

Runs in your browser. Nothing is uploaded.

XML

YAML

How to use it

  1. Paste your XML.
  2. Choose a 2 or 4 space indent.
  3. Press XML to YAML.
  4. Copy the YAML or download the file.

How XML maps to YAML

The tool reads the XML with the same rules as the XML to JSON tool and writes the result as YAML. An attribute becomes a key that starts with @, text next to attributes or child elements goes under #text, and an element that repeats under one parent becomes a list. Because a single element stays a plain value, the shape can differ between documents. An empty element becomes an empty string.

Types and what is dropped

Every value is text; numbers and true or false are not converted. YAML quotes the strings that would otherwise be read as another type, such as "1" or "y", so they stay strings. Comments, processing instructions, the XML declaration and the DOCTYPE are not carried over. Only the five built-in entities and numeric references are decoded, and other entities are an error. Nothing is validated against a schema.

Error messages and what to do

MessageWhat it meansFix
No root element found. XML needs one element such as <root>...</root>The input has no XML element.Paste well-formed XML with one root element.

Questions people ask

How do I convert XML to YAML?

Paste the XML and press XML to YAML. Elements become keys, repeated elements become lists, and attributes appear as @name keys. Copy the YAML or download it as a .yaml file.

Where do attributes go?

Each attribute becomes a key that starts with @, next to the element's children. Text that sits beside attributes or children is stored under the key #text.

Why is a single child not a list?

An element that appears once stays a single value, and one that repeats becomes a list. So the same element can be a mapping in one file and a list in another. Check that your consumer allows for both.

Are numbers converted?

No. Every value is text. YAML quotes strings that look like other types, so "1" appears as '1' and stays a string when you load the YAML.

Is it the same as converting XML to JSON first?

The structure matches the XML to JSON tool, since it uses the same reader. The output is YAML instead of JSON, with quoting handled for you.

About this tool

Reads the XML with the same rules as the XML to JSON tool and then writes the result as YAML. The root element is the one top-level key. An attribute becomes a key that starts with @, text next to attributes or child elements goes under #text, and an element that repeats under the same parent becomes a list, so the shape can differ between documents. All values are text: numbers and true or false are not converted, and YAML quotes the ones that would otherwise be read as another type (for example "1" and "y"). An empty element becomes an empty string. Comments, processing instructions, the XML declaration and the DOCTYPE are dropped, and only the five built-in entities and numeric references are decoded. It does not validate against a schema.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.