XML to YAML

Turn XML into readable indented YAML.

Reverse
Input
XML input
Output
Result
Options

Attributes are prefixed with @_ so they stay distinct from elements.

Values with leading zeros stay strings so IDs are preserved.

Spaces per level of nesting.

About this tool


XML to YAML trades angle brackets for indentation, which usually makes a document considerably shorter and easier to read, closing tags disappear entirely, and so do most quotes.

The mapping follows the same rules as XML to JSON, because both targets share one data model. The same caveat therefore applies: XML cannot distinguish a single item from a one-item list.

How to use it

  1. Paste or upload XMLDrop a .xml file onto the input pane, use the file picker, or paste the text directly.
  2. Adjust the options if neededThe defaults suit most input. Open Options to change how values are interpreted or formatted.
  3. ConvertPress Convert to YAML, or use Ctrl+Enter (Cmd+Enter on macOS).
  4. Read any warningsWarnings explain anything that could not be represented exactly in the target format.
  5. Copy or downloadCopy the result, or download it as a .yaml file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

XML to YAML

Input

<config>
  <host>localhost</host>
  <ports><port>80</port><port>443</port></ports>
</config>

Output

config:
  host: localhost
  ports:
    port:
      - 80
      - 443

The repeated <port> elements become a YAML sequence.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

Elements become mappings, repeats become sequences
Each element becomes a YAML key. An element appearing once produces a single value; the same element repeated produces a hyphenated sequence. Since nothing in the XML states which was intended, the output shape depends on the data, and consumers should handle both.
Attributes keep the @_ prefix
Attributes are written as keys prefixed with @_ so they cannot collide with a child element of the same name. Turn off "Keep attributes" to discard them entirely if they carry no meaning in your document.
Text content and quoting
An element containing only text becomes a plain scalar. Where text sits alongside child elements, it appears under a #text key, and the original interleaving is lost. Values that YAML would reinterpret, "true", "01234", are quoted automatically so they stay strings.
Why YAML output is usually shorter
XML repeats every element name in its closing tag; YAML names each key once. On a deeply nested document the saving is substantial, which is part of why configuration formats moved away from XML.

Limitations


  • A single element and a one-element list are indistinguishable.
  • Mixed-content ordering is lost.
  • Comments, DTDs and processing instructions are discarded.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


Why is a single element not a list?
XML has no way to say "this is a list of one". One occurrence becomes a scalar and two become a sequence, so normalise in your consumer if the count can vary.
Can I drop the @_ attribute prefixes?
Turn off "Keep attributes" to remove attributes altogether. The prefix itself is fixed, because it prevents silent collisions with child elements.