Convert YAML to XML — anchors, multiple documents and attributes included
The YAML to XML converter turns YAML — Kubernetes and Docker Compose files, Ansible variables, OpenAPI specs, CI pipelines, translation files, Jekyll and Hugo front matter — into well-formed XML for systems that only read XML: integration platforms, XSLT transforms, Maven or .NET configuration, SOAP services and older import tools.
Your YAML is read with the open-source js-yaml library (MIT licence) using the YAML 1.2 core schema. Anchors and aliases are resolved, << merge keys are applied, block scalars keep their line breaks, and a file with several --- documents can become several children of one root element. The data is then written with the same rules as our JSON to XML converter: keys starting with @ become attributes, #text becomes element text and lists repeat their element.
Errors show the line and column. The conversion runs in your browser — only js-yaml itself is fetched from a public CDN, and your YAML is never uploaded.
How to use the YAML to XML Converter
- Paste YAML into YAML input, drop a .yaml or .yml file on the box, or press Open file.
- Set the Root element. With “Use a single top-level key as the root” ticked, a file that starts with one key such as
service:uses it as the root. - Choose what happens with Several YAML documents: all of them as children of the root, or only the first.
- Adjust attributes, the text key, arrays,
nullhandling, invalid names, indent and the XML declaration if needed. - Press Copy or Download XML. Swap opens the XML in the XML to YAML converter so you can compare.
YAML to XML Converter features
YAML 1.2 core schema
yes, no, on and off stay words, dates stay as written, 0x1F and 0o17 become 31 and 15, and .inf and .nan become INF and NaN as XML Schema writes them.
Anchors and merge keys
Every *alias is replaced by the anchored value and <<: *defaults is merged in, so the XML shows the settings each section really gets.
Multi-document files
Each --- document becomes a child of the root: a document with a single key uses that key as the element name, others are wrapped in <document>.
Attributes from YAML
Write "@id": 7 (quoted, because @ cannot start a plain YAML key) and it becomes id="7". Grouped _attributes maps work too.
Text kept intact
Literal | blocks keep their line breaks, folded > blocks are joined as YAML defines, and &, < and > are escaped.
Precise errors
Bad indentation, tabs, duplicated keys, unclosed quotes and self-referencing aliases are reported with the line, column and a snippet.
How YAML maps to XML
YAML comments are not part of the data, so they are not carried into the XML. Numbers and booleans become text because XML has no types of its own; converting back with XML to YAML and “Convert numbers & booleans” ticked restores them.
| YAML | XML |
|---|---|
owner: Asha Rao | <owner>Asha Rao</owner> |
"@version": 2.4.1 | the attribute version="2.4.1" |
ports: [80, 443] | <ports>80</ports><ports>443</ports> |
web: {<<: *defaults, port: 8080} | <web><timeout>30</timeout>…<port>8080</port></web> |
notes: | with two lines | <notes> containing both lines |
cache: with no value (null) | <cache/>, xsi:nil="true" or nothing |
Two documents separated by --- | <root><document>…</document><feature>…</feature></root> |
Converting configuration files
To switch between YAML and JSON instead, use the YAML ↔ JSON Converter; to pretty-print or validate the XML you get, use the XML Formatter.
- One root element. XML needs exactly one. Several top-level keys are wrapped in the root element you name; a single key becomes the root itself.
- Keys that are not XML names. Kubernetes labels like
app.kubernetes.io/nameand Compose ports like8080/tcpbecomeapp.kubernetes.io_nameand_8080_tcp. Choose “Encode as _xHHHH_” if you need to recover the exact keys later. - Lists of maps. A list such as
containers:becomes repeated<containers>elements; choose “Wrap items in the element” for<containers><item>…</item></containers>. - Secrets. Values stay on your device, but double-check what you paste into any other site — this page never sends it anywhere.
YAML to XML Converter FAQ
How do I convert YAML to XML?
Paste your YAML or open the .yaml file. The YAML to XML conversion appears instantly on the right; set the root element and other options, then copy the XML or download it.
How do I create an XML attribute from YAML?
Use a key that starts with @ and put it in quotes, because @ is reserved at the start of a plain YAML key: "@id": 7 becomes id="7" on the parent element.
What happens with several YAML documents in one file?
By default every document becomes a child of the root element. A document with one top-level key uses that key as the element name; others are wrapped in <document>. You can also convert only the first document.
Are anchors, aliases and merge keys supported?
Yes. Aliases are expanded to the anchored value and << merge keys are applied before conversion. An alias that refers to the node containing it is reported as an error, because XML cannot represent a loop.
Why did some of my keys change?
XML element names cannot contain slashes, spaces or most punctuation and cannot start with a digit, so those characters are replaced with underscores. Pick “Encode as _xHHHH_” for a reversible encoding.
Is my YAML uploaded?
No. The YAML is parsed and converted in your browser; only the open-source js-yaml library is downloaded, and your file stays on your device.