This is two conversions run back to back, not a separate direct one: the XML is parsed into the same @-attribute / #text / repeated-tag JSON representation that /xml/to-json produces, and that value is then written out as YAML instead of JSON. Every rule and every limitation documented on /xml/to-json applies here identically — this page exists because "xml to yaml" is a search someone actually types, not because the underlying conversion is any different.
The example reuses the same product feed as /xml/to-json, so you can compare the two outputs directly: same @sku and #text keys, just written as YAML mappings instead of JSON objects.
Before and after
This is loaded in the converter above.
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product sku="SKU-100">
<name>Wireless Mouse</name>
<price currency="BRL">129.90</price>
</product>
<product sku="SKU-204">
<name>Mechanical Keyboard</name>
<price currency="BRL">349.00</price>
</product>
</products>products:
product:
- '@sku': SKU-100
name: Wireless Mouse
price:
'@currency': BRL
'#text': '129.90'
- '@sku': SKU-204
name: Mechanical Keyboard
price:
'@currency': BRL
'#text': '349.00'
How the mapping works
Attributes and text follow the XML to JSON convention exactly
@sku: SKU-100 and #text: '129.90' below are the same @-prefixed-attribute and #text-content keys documented on /xml/to-json, just rendered in YAML's key: value syntax instead of JSON's "key": "value". Quoting on the YAML side follows the usual YAML rule: '@sku' is quoted because a key starting with @ needs it, and '129.90' is quoted so it stays a string rather than being read back as a number.
Repeated elements become a YAML sequence
Two sibling <product> elements become one product: key holding a YAML sequence (- @sku: ... / - @sku: ...) — the array step happens during XML parsing, exactly as on /xml/to-json; only the final serialization step differs.
Numbers from XML stay quoted strings in the YAML
129.90 above comes out as the quoted YAML string '129.90', not the bare number 129.9 — because it was never a number to begin with. XML text is always characters (see /xml/to-json's mapping for why this converter doesn't guess otherwise), so the YAML step has a string to serialize, and quotes it the same way it would quote any string that happens to look numeric.
Known limitations
- Every limitation on /xml/to-json applies here first, before YAML is even involved: mixed content loses ordering, namespaces are treated as literal string prefixes, comments are dropped, and every XML text value becomes a string rather than being parsed into a number or boolean.
XML to YAML FAQ
Is this a different conversion from XML to JSON?
No — it parses the XML using the exact same rules, then serializes the result as YAML instead of JSON. Every mapping rule and limitation is shared with /xml/to-json.
Why are some keys quoted in the YAML output, like '@sku'?
YAML requires quoting a plain scalar that would otherwise be ambiguous — a key starting with @ is one such case. It's a YAML syntax requirement, not something this converter adds on top.
Is my XML uploaded anywhere?
No. Both the parsing step and the YAML serialization run in your browser.
Other conversions
Every direction between JSON, XML and YAML — including YAML as a starting point — is available directly from the From/To selectors in the converter above, whichever page you're on.