XML to YAML
What is an Xml To Yaml?
XML is verbose: every value is wrapped in an opening and closing tag. YAML expresses the same hierarchy with indentation alone, which makes it far easier to read and edit. Converting XML to YAML is useful when migrating configuration to tools that use YAML, such as Kubernetes, Ansible and CI systems, or simply to read a large XML document more comfortably.
How to use it
- Paste well-formed XML.
- Copy the YAML output.
Example
Input:
<server>
<host>0.0.0.0</host>
<port>8080</port>
<feature>auth</feature>
<feature>metrics</feature>
</server>Output:
server:
host: 0.0.0.0
port: '8080'
feature:
- auth
- metricsMapping rules
- Nested elements become nested mappings.
- Repeated elements become sequences (lists with dashes).
- Attributes are kept with a prefix such as
@or_, depending on the converter conventions. - Values come from XML text, so they may be quoted strings even when they look like numbers.
After converting
- Rename keys to match the schema your target tool expects; a direct conversion rarely matches another tool's format exactly.
- Convert numeric and boolean strings to real types where the target needs them.
- Validate the final YAML, for example with
kubectl apply --dry-run=clientfor Kubernetes manifests. - Comments and processing instructions from the XML are not carried over.
Frequently Asked Questions
Why convert XML to YAML?
YAML is shorter and easier to read and edit, and many modern tools such as Kubernetes and Ansible use it for configuration.
How are repeated XML elements converted?
They become a YAML list, with each item on its own line starting with a dash.
What happens to XML attributes?
They are kept as keys with a prefix such as @ so they can be told apart from child elements.
Are XML comments preserved?
No. Comments are not part of the converted data.