XML → YAML Converter
Convert XML to YAML via JSON. Attributes are flattened; namespace prefixes are dropped.
How the conversion works
XML is converted to YAML via two steps: XML → JSON (using the XML parser), then JSON → YAML. The XML parser flattens element content and attributes into a JSON object, which is then serialised as YAML. Namespace prefixes are dropped during parsing.
Input
<?xml version="1.0"?>
<server>
<name>api-prod</name>
<port>8080</port>
<features>
<item>auth</item>
<item>logging</item>
</features>
</server>Output
server:
name: api-prod
port: '8080'
features:
item:
- auth
- loggingAttribute and namespace handling
| XML construct | YAML output | Notes |
|---|---|---|
| Element text content | String value | Under the element key |
| Attribute | Flattened to sibling key | Merged with child elements |
| Namespace prefix (ns:x) | Key without prefix (x) | Prefix dropped |
| Default namespace | No key modification | Ignored in output |
| CDATA section | Plain string | Markup stripped |
| Processing instruction | (dropped) | Not in JSON/YAML data model |
| XML comment | (dropped) | No YAML equivalent |
| Repeated elements | YAML sequence | Same-name siblings → array |
Note: XML attributes and child elements share the same key namespace in the JSON intermediate representation. If an attribute and a child element have the same name, the child element value wins (it overwrites the attribute).
Handling mixed content
XML supports mixed content — elements that contain both text and child elements. This has no direct equivalent in YAML. The converter places the text content under a #text key alongside child element keys. If there are no child elements, text content becomes the direct string value.
Input
<description>A <strong>bold</strong> statement</description>
Output
description: '#text': A statement strong: bold
Frequently Asked Questions
Your files stay on your computer. Dad promised.