YAML to XML Converter

Convert YAML into well-formed XML. Mappings become elements, lists become repeated elements, and keys starting with @ become attributes.

Updated
Runs in your browser. Your data is not uploaded.

Used when the YAML has more than one top-level key.

Converts as you type for inputs up to 200 KB.

How to use the YAML to XML Converter

  1. Paste YAML into YAML input, or upload or drop a .yaml or .yml file.
  2. Set the Root element used when the YAML has more than one top-level key, and the Indent.
  3. Press Convert, then copy the XML or download converted.xml.

How it works

  • The YAML is parsed with a YAML 1.2 parser. Anchors and aliases (&base, *base) and merge keys (<<) are expanded first.
  • Each mapping key becomes an element. A list under a key repeats that element once per item.
  • Keys written as '@name' become attributes of their parent, and '#text' becomes its text.
  • Numbers, booleans, and dates are written as their YAML text. null and ~ become empty elements.
  • When the YAML has a single top-level key, it becomes the root element. Otherwise the output is wrapped in the root you choose.

Examples

Input:

server:
  '@env': production
  host: example.com
  ports:
    - 80
    - 443
  tls: true

Output:

<?xml version="1.0" encoding="UTF-8"?>
<server env="production">
  <host>example.com</host>
  <ports>80</ports>
  <ports>443</ports>
  <tls>true</tls>
</server>

Limitations

  • Only the first document of a multi-document YAML file (separated by ---) is converted.
  • YAML comments are lost, because they are not part of the data.
  • Custom tags such as !Ref in CloudFormation templates are not supported.
  • Files are limited to 5 MB.

Frequently asked questions

How do I create an XML attribute in YAML?

Use a quoted key that starts with @, such as '@id': 42. Quotes are needed because @ can't start a plain YAML key.

Why does my YAML fail to convert?

The most common causes are tabs used for indentation, inconsistent indent levels, and a colon inside an unquoted value. The error shows the line and column.

What happens to anchors and aliases?

They are expanded, so each alias is written out in full in the XML.

Is my YAML uploaded?

No. It is converted in your browser.

Often used together with the YAML to XML Converter.