XML to YAML Converter

Paste XML and get back the equivalent, readable YAML, useful whenever you're migrating a legacy XML config or feed into a YAML-based system. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

Migrating a config format from XML to YAML usually starts with the tedious part: manually re-typing the same data in a new syntax. This converter parses XML and produces the equivalent YAML directly, attributes, repeated elements, and nested structure all included.

It's built around a small custom XML parser rather than the browser's DOMParser, specifically so it works the same way whether the page is being pre-rendered on a server during a build or run live in a browser tab.

What Is XML to YAML Converter?

An XML-to-YAML converter reads XML markup, elements, attributes, and text content, and represents the same information as a YAML mapping, using `@attribute` keys for attributes and grouping repeated sibling elements into sequences.

Because XML's data model is slightly richer than YAML's (it distinguishes attributes from child elements, and supports mixed text-and-element content), the converter uses a couple of explicit conventions, `@name` for attributes and `#text` for element text alongside attributes, to carry that extra information across without losing it.

How XML to YAML Converter Works

The XML is tokenized into tags and text, then assembled into a tree using a stack that tracks open elements. Once the tree is built, it's converted into a plain JS value: attributes become `@`-prefixed keys, repeated sibling tags become arrays, and the resulting value is serialized as block-style YAML.

Because the parser doesn't rely on a browser API, the exact same conversion logic runs during this page's own build process and in a visitor's browser, so there's nothing that only works in one environment.

When To Use XML to YAML Converter

Use it when migrating a legacy XML config, feed, or fixture to a YAML-based system.

It's also useful for quickly reading the actual structure of an unfamiliar XML document, since YAML's indentation-based syntax is often easier to scan than nested angle brackets.

Features

Advantages

  • Runs entirely client-side.
  • Preserves XML attributes explicitly, rather than silently discarding them.
  • Groups repeated sibling elements into YAML sequences automatically.
  • Reports the exact line and column of the first structural problem in malformed XML.

Limitations

  • Mixed content (text interleaved with child elements in the same parent) keeps only the text, not its position relative to the child elements.
  • XML namespaces are treated as part of the tag name rather than resolved separately.
  • XML comments and processing instructions are discarded, since YAML has no equivalent slot for them in this conversion.

Examples

Repeated elements become a sequence

Input

<root>
  <name>api</name>
  <env>prod</env>
  <env>staging</env>
</root>

Output

root:
  name: api
  env:
    - prod
    - staging

The two sibling <env> elements collapse into a single env key holding a two-item list.

Attributes become @-prefixed keys

Input

<user id="1">Ada</user>

Output

user:
  "@id": "1"
  "#text": Ada

The attribute and the element's text content are both preserved, under @id and #text respectively.

Mismatched closing tag

Input

<root><a>1</b></root>

Output

Expected closing tag </a> but found </b>

The parser reports exactly which closing tag it expected instead of silently misreading the structure.

Best Practices & Notes

Best Practices

  • Check for `@`-prefixed keys in the output if the source XML used attributes; they carry real data, not metadata to discard.
  • Validate the source XML in a dedicated XML tool first if you're unsure whether it's well-formed.
  • Use the YAML Formatter afterward if you want a different indent width than the default.

Developer Notes

Parsing is handled by a small hand-written tokenizer and stack-based tree builder (no DOMParser, no XML library dependency), specifically so it behaves identically during this site's static build (Node.js, no DOM) and in a visitor's browser. Attributes are surfaced as `@name` keys and text content as `#text` when an element has both attributes and text, a common, low-ambiguity XML-to-object convention.

XML to YAML Converter Use Cases

  • Migrating a legacy XML config file to YAML
  • Converting an XML data feed into YAML for a YAML-based pipeline
  • Reading the actual structure of an unfamiliar or deeply nested XML document

Common Mistakes

  • Overlooking `@`-prefixed keys in the output and assuming attribute data was dropped.
  • Feeding in XML with mismatched tags and expecting a partial, best-effort result rather than an error.

Tips

  • Use the reported line and column to jump straight to a malformed tag.
  • Pair this with the YAML to XML Converter to round-trip and sanity-check a conversion.

References

Frequently Asked Questions