spaces
XML Input XML
โš ๏ธ Invalid XML โ€” please check your input.
YAML Output YAML
Advertisement
What does an XML to YAML converter do? An XML to YAML converter reads an XML document and rewrites the same tree as YAML. This one uses your browser's XML parser, shows attributes as @name keys, turns repeated sibling tags into lists, and guesses numbers, booleans and null from text. Nothing is uploaded.

What does an XML to YAML converter do?

XML and YAML can describe the same tree, but they look nothing alike. XML repeats every name in an opening and closing tag. YAML uses indentation and a colon. That is why people convert older XML configuration into YAML when they move to tools that expect it.

This XML to YAML converter hands your text to the browser's own XML parser (DOMParser). If the XML is not well-formed, you get an error message and no output. Otherwise each element becomes a key. Attributes become keys that start with @, such as @id. Text that sits beside attributes goes under #text. Tags that repeat under the same parent become a YAML list.

Know the catches. A tag that appears only once is not a list, even if the real schema allows many. Text mixed in between child elements is dropped. Values that look like numbers, true, false or empty become YAML numbers, booleans or null, so 007 turns into 7. If you are going the other way, use the YAML to XML converter.

How to convert XML to YAML here

  1. Paste your XML into XML Input, or press Sample to load a person record with attributes and a hobbies list.
  2. Pick Indent: 2 or 4 spaces.
  3. Leave Include attributes (as @attr) ticked to keep attributes, or untick it to drop them.
  4. Tick Strip root element if you do not want the outermost tag as the first YAML key.
  5. Click Convert. A red message means the XML failed to parse.
  6. Press Copy, or Download .yaml to save output.yaml.

What this XML to YAML converter handles

Attributes as @keys

An attribute like id="1" becomes "@id": 1. Keys starting with @ are quoted so the YAML stays valid.

Repeated tags become lists

Several <hobby> siblings turn into a YAML sequence with one dash per item. List items that are objects are indented correctly.

Text beside attributes

When an element has both attributes and text, the text is stored under #text so nothing is lost.

Type guessing

The words true and false become booleans, and numbers become numbers. Empty or whitespace-only elements and the word null become null.

Strip root

Removes the outer tag so a <config> wrapper does not appear as a key in the YAML.

Safe quoting

Strings with colons, hashes, brackets, leading dashes or words like yes and no are quoted so YAML tools read them as text.

Who needs XML turned into YAML

  • Moving legacy config to a YAML-based platform. You have an old XML settings file and the new tool wants YAML. Convert it, then rename keys to the new schema by hand.
  • Reading an XML feed more easily. A sitemap or API response is hard to scan with all those closing tags. YAML puts the same structure in far fewer lines.
  • Preparing test data. Developers can turn an XML fixture into YAML for a test suite that already loads YAML.
  • Checking how a tree is shaped. Seeing which tags became lists and which became single keys reveals how an XML document is really structured.

Tips: attributes, lists and type guessing

  • Single occurrences do not become lists. If a feed has one <item> today and many tomorrow, the YAML shape changes. Plan for that in your code.
  • Quote values you want to stay text. XML has no types, so 007, 1e3 and 0x10 are read as numbers.
  • Mixed content, such as

    Hello <b>you</b>

    , loses the loose text. This tool is for data XML, not documents.
  • Namespace prefixes stay in tag names (like dc:title), and xmlns attributes show up as @xmlns when attributes are on.
  • Comments and processing instructions are ignored. If your source is JSON instead, the JSON formatter and JSON to TOML pages cover that side.

Is it safe? Privacy and limits

Parsing and conversion run in your browser with the built-in DOMParser and a few lines of JavaScript. Your XML is not uploaded and there is no account. The converter does not check against a DTD or XSD and does not fetch external entities. Because it makes guesses about types and drops mixed text, review the YAML before using it in a production system.

XML to YAML converter FAQ

Each attribute becomes a key with an at sign in front, for example @id or @class, placed inside the element's mapping before the child elements. In the YAML they appear in quotes, as "@id": 1, because a plain scalar cannot start with @. If an element has attributes and text, the text is stored under #text. You can switch this off with the Include attributes checkbox, in which case attributes are simply left out and only elements and text remain.

The converter groups sibling tags by name. If a name appears more than once under the same parent, it becomes a YAML list. If it appears once, it becomes a plain key, because the tool cannot know the schema allows more. This is the main surprise in XML to YAML conversion. If you need a list every time, add a dummy second element, or fix the structure in your own code after loading the YAML.

It removes the outermost tag from the output. Without it, a document with a config tag wrapping a port tag becomes a config key with port: 80 indented below it. With it ticked, you get port: 80 at the top level. This is handy when the root tag is only a wrapper. The root's own attributes are still kept, because they are read from that element. If you strip the root and the XML has an attribute on it, those keys appear at the top.

The converter guesses types from text. The strings true and false become booleans, anything that JavaScript's Number() accepts becomes a number, and an empty or whitespace-only element or the word null becomes null. That is why 007 becomes 7, 1e3 becomes 1000 and 0x10 becomes 16. XML itself carries no types, so this is a convenience that can cost you leading zeros, such as in zip codes. Check identifiers and codes after converting.

It is dropped. When an element contains child elements, the converter builds keys only from those children, and any loose text around them is ignored. So a paragraph with bold tags loses the words outside the bold part. Text is only kept when an element has no children, either as the value itself or under #text beside attributes. This tool is meant for data-style XML such as configs and feeds, not marked-up prose like XHTML.

Namespace prefixes are kept as part of the tag name, so dc:title stays dc:title, and xmlns declarations appear as @xmlns keys when attributes are included. CDATA sections are read as their text content. Comments and processing instructions, including the xml declaration, are ignored. DTD and XSD validation is not performed, and external entities are not loaded. For documents that rely heavily on namespaces you may want to tidy the keys by hand afterwards.

The output is plain block-style YAML, readable by common parsers. It does not use anchors, flow style or multi-line block scalars. Strings that could be misread are put in double quotes, including yes, no, on, off and strings with a colon or hash. Empty objects are written as {} and empty lists as []. If your tool reads YAML 1.1 and has its own quirks, test with a small file first.

It is free and needs no signup. The XML never leaves your browser: parsing, type guessing and writing the YAML all happen locally. There is no upload step, no stored history and no usage cap in the code, so you can convert as many files as you like. If you work with confidential files, you can still do this offline once the page has loaded. The Download .yaml button creates output.yaml on your device, nothing more.

Read the YAML against the original once, looking at three places: single tags that should be lists, numbers that should stay strings, and any dropped mixed text. Then rename keys to match the target system, and validate the file with that system's own linter. If the source XML is messy, tidy it first with the HTML formatter, which also re-indents markup-style XML. If you need to go back to XML later, the YAML to XML converter on this site can do the reverse for simple data, and JSON to XML covers JSON sources. Both are covered by the same caveats on types.

Advertisement