How to convert YAML to XML
YAML describes data with maps, lists and values. XML describes it with elements, attributes and text, and it needs exactly one root element. To convert yaml to xml, a tool has to choose a root, turn each key into an element and decide what a list looks like. This converter makes those choices visible and lets you change them.
Take this YAML:
config:
"@version": 2
name: Demo & Co
tags:
- red
- blue
"max users": 50
note:With the default settings it writes:
<?xml version="1.0" encoding="UTF-8"?>
<config version="2">
<name>Demo & Co</name>
<tags>red</tags>
<tags>blue</tags>
<max_users>50</max_users>
<note/>
</config>The @version key became an attribute. The ampersand was escaped. The list was written as two tags elements. The key max users has a space, which XML names cannot hold, so it became max_users and was listed in the notes. The empty note became a self-closing element.
Choosing the root element
An XML file has one root element, and a YAML file does not have to. With the Root element box empty, the tool uses the top-level key when there is only one, as config above. When there are several top-level keys, they are wrapped in a root element:
<root>
<name>Ana</name>
<age>31</age>
</root>Type a name such as person into the box and it is used instead, so the same YAML gives <person>. A top-level list is wrapped as well, with one item element for each entry. If the name you type is not a valid XML name, it is cleaned and listed in the notes.
How lists are written in XML
XML has no list type, so a YAML list becomes repeated elements. Lists has two modes.
- Repeat the key writes one element per item, all named after the key. This is the usual way XML data repeats a value, and it is what XML to YAML reads back as a list.
- Wrap in <item> writes one element for the key and puts an item element inside it for each entry.
<config>
<tags>
<item>red</item>
<item>blue</item>
</tags>
</config>That is the Wrap result for the tags list. An empty list writes nothing in either mode, because XML cannot say empty list, and the notes count how many were skipped. A list inside a list always uses item elements for the inner list.
Attributes, text and null values
A key that starts with the attribute prefix, @ by default, becomes an attribute of its parent element, so "@id": 7 writes id="7". Quote such keys in YAML, because a bare @ cannot start a plain value. Choose _ or - as the prefix to avoid quotes, or None to write every key as an element. The setting matches the one in XML to YAML, so the round trip keeps attributes as attributes.
- A key named #text, or the name you set in Text key, becomes the text of its element next to attributes or child elements.
- null and empty values become a self-closing element, such as <note/>. An empty string becomes an element with no text between the tags.
- Numbers and booleans are written as their text, so true stays true.
- A prefixed key that holds a map or list cannot be an attribute. It is written as an element and the notes count it.
Keys that are not valid XML names
Element names cannot contain spaces, cannot start with a digit, hyphen or dot, and may use a colon only for a namespace prefix. YAML keys have no such limits. The converter replaces each invalid character with an underscore, adds an underscore in front of a name that starts badly, and writes a list of every rename in the Renamed keys panel.
<root>
<_1st_place>gold</_1st_place>
<first_second>silver</first_second>
<a_b>bronze</a_b>
</root>Those are the results for the keys 1st place, first/second and a:b. A colon is kept only when its prefix is declared, for example by an @xmlns:s attribute on the same or a parent element. Without a declaration the colon would make the XML invalid for strict readers, so it is replaced. If two attributes end up with the same name after cleaning, a number is added to the second.
Special characters, several documents and the well-formed check
Ampersands, angle brackets and quotes are escaped. Line breaks inside attributes are written as character references. Characters that XML 1.0 cannot hold at all, such as control characters, are left out and counted in the notes, so the output stays valid.
A YAML file can hold several documents separated by ---. XML needs one root, so when the file has more than one document, each is written as a document element inside the root. The notes say how many were found.
After converting, the page reads its own output back with a strict XML parser and shows the result under Check. Passing means the output is well-formed, with matching tags, quoted attributes and one root. It does not mean the XML fits a schema, a SOAP service or a particular program.
Indent, declaration and limits
Choose 2 spaces, 4 spaces, a tab or minified output on one line. The XML declaration line can be switched off when you need a fragment to paste into another file. Anchors, aliases and merge keys in the YAML are resolved before writing, and comments are dropped because they are not data.
The tool does not generate an XSD or a SOAP envelope, and it does not fetch anything. Nesting deeper than 400 levels is refused with a message.
Privacy
YAML files often hold hostnames and secrets. The conversion runs in your browser and the text is not uploaded. The Privacy Policy explains what the site stores. Replace real secrets with placeholders before you share a file.
Related tools: YAML to JSON, YAML to Properties and JSON to YAML.