How to convert XML to YAML
XML and YAML both describe nested data, but they do not have the same parts. XML has elements, attributes, text and comments. YAML has maps, lists and values. To convert xml to yaml, a tool has to decide where each XML part goes, and those decisions are the whole job.
This converter makes the decisions visible and lets you change them. Take this small file:
<server port="8080" secure="true">
<host>app.example.com</host>
<user>ana</user>
<user>bo</user>
<build>007</build>
</server>With the default settings it writes:
server:
"@port": 8080
"@secure": true
host: app.example.com
user:
- ana
- bo
build: "007"The two attributes became keys that start with @. The two user elements became a list. The port became a number, and 007 stayed text so it keeps its zeros.
How XML attributes are written in YAML
YAML has no attributes, so each attribute becomes a key inside the map of its element. A prefix keeps attributes apart from child elements. Without it, an element with an id attribute and an id child would collide.
- Prefix @ is the usual convention. YAML puts quotes around keys that start with @, so you will see "@port".
- Prefix _ and prefix - need no quotes, which reads cleaner in a config file.
- No prefix writes attributes as plain keys. If a child element has the same name, an underscore is added to the second key and the notes say so.
An element that has attributes and also text keeps its text under a key you can name. The default is #text, and you can change it to value or anything else. YAML to XML reads the same prefix and text key, so the conversion can go back.
What happens to repeated elements
A YAML map cannot hold the same key twice, so elements with the same name next to each other become one key with a list. A single element stays a plain value, which is why the same file can give a value in one place and a list in another.
If you want predictable shapes, set Repeated elements to Always a list. Then even one item is written as a list:
list:
item:
- oneWhen same-name elements are not side by side, for example b, c, b, they are grouped under one key at the position of the first one. The notes tell you when that reordering happened. Order between different names is kept.
Numbers, booleans and values like 007
XML stores only text. With Detect numbers and booleans, a plain number is written as a number and true or false as a boolean. A number is detected only when it prints back exactly as it was typed, so 8080 and 2.5 become numbers, while 007, 1.50 and 12345678901234567890 stay text.
Text that YAML would misread is quoted. Older YAML 1.1 parsers, still common in Kubernetes and Compose tooling, read yes, no, on and off as booleans, so those words are written as "yes" and "no". Choose Keep everything as text to quote every value that could be read as something else.
Namespaces, CDATA, comments and DOCTYPE
Namespace prefixes are kept by default, so s:Body stays s:Body and the xmlns declaration is written as an attribute. Strip prefixes removes both, which gives shorter keys when you do not need the namespace:
Envelope:
Body:
GetPrice:
Item: AppleThat example is a SOAP envelope. Stripping prefixes can merge two names that differed only by prefix, and the notes warn you.
- CDATA sections are read as ordinary text and written as a YAML string.
- Comments and processing instructions are dropped, because the mapping has no place for them. The notes count them.
- A DOCTYPE is skipped. Nothing is fetched from it, and custom entities defined in it are not expanded. An unknown entity is reported as an error.
- Text between child elements, as in <p>Hello <b>big</b> world</p>, is joined and written under the text key. The position of the child inside the sentence is lost, and the notes list this as mixed content.
XML to YAML for Maven, Spring and Android files
Build and config files are the usual reason to convert. A pom.xml becomes a nested YAML map with a dependency list. A Spring beans file becomes a list of beans with attribute keys for id and class. An Android strings.xml gives a string list in which each item has a name attribute and the text under the text key. The samples under the input box load each of these.
The result is a faithful picture of the XML, not a file for a particular tool. A YAML file for Spring Boot or Kubernetes has its own structure, so expect to reshape the output by hand. The mapping notes show you what the converter had to decide.
Errors and limits
The reader is strict. A closing tag that does not match, an attribute without quotes, an ampersand that is not part of an entity or a second root element stops the conversion, and the message names the line and column and says what to fix. It reads XML 1.0 text. It does not validate against a schema or DTD, run XSLT or query with XPath.
Nesting deeper than 400 levels is refused. Very large files take time, so for files of many megabytes a command-line tool is a better fit.
Privacy
Config files often hold hostnames, passwords and tokens. The conversion runs in your browser and the XML is not uploaded. The Privacy Policy explains what the site stores. Replace real secrets with placeholders before you share a file.
For other formats, see YAML to JSON, JSON to YAML and Properties to YAML.