Skip to content
ToolPlankDEV
JSON Tools
100% In-Browser Execution

Updated:

YAML to XML Converter

Paste YAML and get indented XML as you type. This yaml to xml converter lets you pick the root element, how lists and attributes are written and the indent, fixes keys that XML cannot use, lists every rename and checks the result is well-formed. Nothing is uploaded.

Options:

YAML

Input
0 chars · 0 lines

XML

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Notes

Renamed keys, documents and the well-formed check appear here once there is a result.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use YAML to XML

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste or open your YAML

    Paste the YAML into the left box, press Paste, or press Upload and choose a .yaml or .yml file. Sample loads an order with attributes, a list and awkward keys. Round trip, Several documents and Awkward keys load other cases.

  2. 02

    Check the XML and the notes

    The XML appears as you type. If the YAML has a mistake, the message gives the line and column. The Notes panel lists every key that had to be renamed and shows whether the output passed the well-formed check.

  3. 03

    Set the root, lists and attributes

    Type a root element name or leave it empty, choose how lists are written, pick the attribute prefix and text key, then choose the indent and whether to add the XML declaration.

  4. 04

    Copy or download

    Press Copy to use the XML, or Download to save it as converted.xml. Use the swap button to turn XML back into YAML.

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:

yaml
config:
  "@version": 2
  name: Demo & Co
  tags:
    - red
    - blue
  "max users": 50
  note:

With the default settings it writes:

xml
<?xml version="1.0" encoding="UTF-8"?>
<config version="2">
  <name>Demo &amp; 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:

xml
<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.
xml
<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.

xml
<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.

Frequently Asked Questions

Technical Q&A for YAML to XML

Common questions about edge cases, character encoding, and privacy guarantees.

Paste the YAML into the left box and the XML appears on the right. Check the notes, then press Copy or Download. Set the root element and list style first if the program that reads the XML expects a certain shape.

As repeated elements named after the key, or as an element with an item element for each entry if you choose Wrap in item. XML has no list type, so one of these two shapes is always used.

Because an XML document is a single tree with one top element. If your YAML has several top-level keys, the tool wraps them in a root element, and you can name it yourself.

They are renamed. Spaces and symbols become underscores, a name that starts with a digit gets an underscore in front, and every rename is listed in the notes.

No. Comments are not data, and the XML written here has no comment elements.

Start the key with @, for example "@id": 7, and quote it. That key becomes an attribute of its parent element. Change the prefix in the Attributes option if you prefer _ or -.

Yes. YML is the same format as YAML. Paste the text or upload the .yml file and the XML is written the same way.

Each document is written as a document element under the root, and the notes show how many were found. Empty documents are skipped.

It is well-formed, which the page checks by reading it back. Whether it is valid for a schema or a service depends on that schema, which this tool does not check.

No. The conversion runs in your browser, so the file stays on your device.