What XML to YAML does
XML to YAML reads XML and writes it as YAML. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.
XML to YAML examples
The built-in sample
Input
<users><user id="1"><name>Ada</name></user><user id="2"><name>Lin</name></user></users>Output
users:
user:
- '@id': '1'
name: Ada
- '@id': '2'
name: Lin
This is the input that the Load sample button fills in.
Attribute keys are quoted
Input
<order id="7"><item sku="A1">Pen</item><item sku="B2">Ink & paper</item><note><![CDATA[1 < 2]]></note><paid/></order>Output
order:
'@id': '7'
item:
- '@sku': A1
'#text': Pen
- '@sku': B2
'#text': Ink & paper
note: 1 < 2
paid: ''
Keys that start with @ or # must be quoted in YAML, and "7" is quoted so it stays the string that XML gave us. The empty paid element becomes an empty string.
Each output was produced by running this tool on the input above it.
How it works
Reading XML. The input is parsed with the browser's XML parser. Attributes become keys prefixed with @, text next to attributes or child elements goes into #text, repeated child elements become arrays, and every value is a string because XML has no data types.
Writing YAML. The result is written with js-yaml using two-space indentation. Strings are quoted only when they would otherwise be read as another type, such as a number or boolean.
Details and limits
- Values are carried across without losing anything in ordinary data; the points above list the cases the two formats handle differently.
- Every value is a string, because XML has no types. Values that YAML would otherwise read as numbers or booleans are quoted to keep them strings.
- The root element name is the single top-level key.
- Input that is not valid XML stops the tool, and the status line shows where the problem is. The XML Validator page lists the usual causes.
Questions
Is my data uploaded when I use XML to YAML?
No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.
What does XML to YAML do?
XML to YAML reads XML and writes it as YAML. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.
How does XML to YAML work?
Reading XML. The input is parsed with the browser's XML parser.
Are there any limits I should know about?
Every value is a string, because XML has no types. Values that YAML would otherwise read as numbers or booleans are quoted to keep them strings. The root element name is the single top-level key.
Is there a size limit?
There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.
Does it work on phones, and is it free?
Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.