XML to YAML — Convert XML Data to YAML Format in Your Browser
Convert XML to YAML configuration format. Configurable attribute handling, namespace stripping, and indentation. Runs entirely in your browser.
XML to YAML is a conversion between two formats that rarely meet in the wild. XML is the established interchange format for document-oriented data — SOAP messages, RSS feeds, XHTML documents, financial transaction logs — where the data carries metadata alongside the values. YAML is the configuration language of the DevOps era — Kubernetes manifests, Ansible playbooks, Docker Compose files, CI/CD pipeline definitions — where the data is written by humans and read by machines. The conversion from XML to YAML is most often a one-off task: an API response in XML needs to become a YAML config file for a deployment tool, or an XML dataset needs to be inspected in a more readable format for debugging.
The conversion path goes through JSON as an intermediary. The XML is parsed into a tree, the tree is converted to a JSON object using configurable attribute and namespace conventions, and the JSON is serialised as YAML. The JSON intermediary is invisible but matters for two reasons. First, it means the attribute convention you choose for this tool is the same convention the XML-to-JSON tool uses — the @attr prefix is the default and is the most widely interoperable choice. Second, it means any limitations of the XML-to-JSON mapping (mixed-content handling, namespace collision behaviour) apply to the YAML output as well. The tool does not add new limitations beyond those inherent to the XML format.
For a final hand-off: if the YAML output is going into a Kubernetes or Ansible deployment, validate it with the target tool’s linter (kubectl apply --dry-run or ansible-playbook --syntax-check) before deploying. If the output has deeply nested indentation that is hard to scan, switch to flow style for leaf values to compress the visual depth. If you need the reverse conversion — YAML to XML — the YAML-to-XML tool on this site handles the round-trip with the same configurable conventions.
How to use
Paste your XML
Drop XML content into the input area. The parser validates well-formedness and reports errors inline. Valid XML is converted through an intermediate JSON representation to YAML output.
Choose YAML formatting options
Default indentation is 2 spaces. Switch to 4 spaces for style-guide compliance. Toggle between block style (default, more readable) and flow style (compact, inline brackets) for the output.
Copy or download the YAML
Copy the YAML to your clipboard, or download as a .yaml file. The output is valid YAML 1.2 and opens in any editor with YAML syntax highlighting.
Frequently asked
How are XML attributes converted to YAML?
By default, XML attributes are prefixed with `@` to distinguish them from child elements. `<book id="123"><title>Dune</title></book>` becomes a YAML mapping with keys `@id` and `title`. Alternative attribute conventions (a separate `_attributes` key or stripping) are available in settings.
Does the converter preserve the XML element ordering?
Yes. YAML mappings preserve key order in the YAML 1.2 specification, and the converter emits keys in the same order they appear in the source XML. This matters for configuration files where key ordering carries semantic meaning.
How are XML namespaces treated in the YAML output?
Namespace prefixes are stripped by default, and elements are identified by their local name. If two elements from different namespaces share the same local name, the second one overwrites the first. Enable 'preserve prefix' mode to keep them as distinct keys.
What happens to XML comments in the conversion?
XML comments are discarded. YAML supports comments with the `#` character, but there is no reliable mapping from XML comment positions to equivalent YAML positions. Structure the YAML and add comments manually after conversion.
Limitations
- No YAML anchors or aliasesRepeated XML structures are converted to repeated YAML mappings. The converter does not detect repetition and emit YAML anchors (`&anchor`) and aliases (`*anchor`). Add aliases manually after conversion for DRY configuration files.
- XML entity references beyond the 5 standard ones failOnly `&`, `<`, `>`, `'`, and `"` are decoded. Custom entities defined in a DTD are not expanded, and their presence causes a parse error.
- CDATA and text nodes merge silentlyCDATA sections and regular text nodes are merged into a single string value in the YAML output. The distinction between a CDATA-wrapped value and a plain text value is lost.
Platform notes
- macOS
- For command-line work, `yq -p xml -o yaml input.xml` handles the conversion. The browser tool is the right pick for one-off conversions where installing yq via Homebrew is more setup than the task warrants.
- Linux
- CLI equivalent: `xq . input.xml` (pip install yq) pipes XML through jq to YAML. The browser tool is the right pick for ad-hoc conversion from a chat window or documentation page.
- Web
- All processing runs client-side. The XML content is never uploaded. Works offline once the page has loaded.