Xerobit

XML to YAML Converter

Paste your XML into the box below to convert it to YAML. The tool parses elements, attributes, text nodes, CDATA sections, comments and processing instructions using a hand-written tokenizer that reports the exact line and column of any syntax error. Everything runs locally in your browser so nothing is uploaded to a server.

Paste well-formed XML here.

YAML Output

root:
  item:
    "@id": "1"
    "#text": Hello

How to use the xml to yaml converter

  1. Paste or type your XML into the input area.
  2. The converter parses the markup immediately as you type.
  3. Review the YAML output below the input field.
  4. If there is a syntax error, the message shows the exact line and column.
  5. Copy the resulting YAML for use in configuration files or pipelines.

How the XML to YAML conversion works

The converter reads your XML character by character using a hand-written tokenizer rather than relying on the browser's built-in DOM parser. It recognises opening tags, closing tags, self-closing tags, attributes, text content, CDATA sections, comments and processing instructions. Each recognised piece becomes a node in an internal tree.

Once the tree is built, a second pass walks it and emits YAML. Elements that contain only text become simple key-value pairs. Elements with child elements or attributes are expanded into nested mappings. When multiple sibling elements share the same tag name, they are collected into a YAML sequence (a list marked with hyphens).

For example, the XML <book><title>Guide</title></book> produces book: followed by an indented title: Guide. Attributes are stored under keys prefixed with @, so <book id="1"> becomes "@id": "1" inside the mapping. Every value is a string: numbers, booleans and dates in the XML are written quoted so they are not turned into other YAML types. Empty elements become "", and when an element has attributes or child elements plus its own text, that text goes under a "#text" key.

Error reporting with line and column numbers

When the tokenizer encounters malformed markup, it stops and returns an error message that includes the line number and column where the problem was found. This makes debugging straightforward even in large documents.

Common errors include mismatched closing tags, unquoted attribute values, stray ampersands that do not form a valid entity reference, and unexpected characters inside tag names. Because the parser does not attempt error recovery, the first issue halts processing so you can fix it before continuing.

Supported XML features and limitations

The tokenizer handles the core constructs used in most data-oriented XML files:

  • Elements with nested children and mixed content
  • Attributes on any element
  • Text nodes including whitespace
  • CDATA sections, which preserve their content verbatim
  • Comments and processing instructions, which are silently skipped
  • The five predefined entities: &amp;, &lt;, &gt;, &quot; and &apos;
  • Numeric character references in decimal (&#65;) and hexadecimal (&#x41;) form

DOCTYPE declarations and external entities are not supported. If your document relies on a DTD to define entities, those references will cause a parse error. For very large or schema-validated documents, consider a dedicated command-line tool instead.

Entity decoding and special characters

Before emitting YAML, all recognised entity references are decoded to their corresponding Unicode characters. Numeric references like &#8364; resolve to the Euro sign. Named references are limited to the five built-in XML entities listed above.

In the YAML output, strings that contain characters such as colons, hashes, quotes or leading spaces are automatically wrapped in double quotes with internal quotes escaped. Only simple words and phrases (letters, digits, spaces and a few safe symbols, starting with a letter) are left unquoted; anything that a YAML parser could read as a number, boolean, date or null is quoted, as are control characters (written as escapes). If you need to prepare raw strings for safe inclusion in XML before converting, you can use the xml escape tool first, or reverse the process with xml unescape.

Practical uses for converting XML to YAML

YAML is widely preferred for configuration files in tools like Docker Compose, Kubernetes, Ansible and many CI/CD systems because it is easier to read and edit by hand. Legacy systems, SOAP services and older data feeds often produce XML. Converting that output to YAML bridges the gap between old data sources and modern tooling.

This xml to yaml converter is also handy when you want to inspect the structure of an XML payload quickly. The indented YAML format makes nesting levels visually obvious. If you later need to compare two converted files, the xml diff page can help spot changes in the original markup, while xml viewer lets you browse formatted XML directly.

Worked examples

ExampleInputResult
Simple elementXML input: <greeting>Hello World</greeting>greeting: Hello World /
Nested with attributesXML input: <book id="1" lang="en"> / <title>XML Guide</title> / <author>Jane Doe</author> / </book>book: / "@id": "1" / "@lang": en / title: XML Guide / author: Jane Doe /
List of itemsXML input: <items> / <item>A</item> / <item>B</item> / <item>C</item> / </items>items: / item: / - A / - B / - C /
CDATA and entitiesXML input: <data><![CDATA[<raw>&amp;content</raw>]]></data>data: "<raw>&amp;content</raw>" /

FAQ

Does this tool upload my XML to a server?

No. The entire conversion happens in your browser using JavaScript. Your data never leaves your device.

What happens if my XML has a DOCTYPE declaration?

The parser does not support DOCTYPE or external entities. Remove the DOCTYPE line before pasting your XML, or the tokenizer will report an error at that position.

How are XML attributes represented in the YAML output?

Attributes are placed inside the element's mapping with keys prefixed by the @ symbol. For example, an attribute named id becomes "@id" in the YAML.

Can I convert the YAML back to XML?

This page only handles one direction. Use the yaml to xml tool to perform the reverse conversion.

Why does the error message show a line and column number?

The hand-written tokenizer tracks its position as it reads each character. When it encounters invalid syntax, it reports exactly where the problem starts so you can locate and fix it quickly.

Are repeated XML elements converted to a YAML list?

Yes. When multiple sibling elements share the same tag name, they are grouped into a YAML sequence denoted by hyphens.