What XML to CSV does
XML to CSV reads XML and writes it as CSV. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.
XML to CSV examples
The built-in sample
Input
<users><user id="1"><name>Ada</name></user><user id="2"><name>Lin</name></user></users>Output
@id,name
1,Ada
2,LinThis is the input that the Load sample button fills in.
One row per repeated element
Input
<users><user id="1"><name>Ada</name></user><user id="2"><name>Lin</name><tag>a</tag><tag>b</tag></user></users>Output
@id,name,tag
1,Ada,
2,Lin,"[""a"",""b""]"The users wrapper is removed and each user becomes a row. The id attribute becomes the @id column, and the two tag elements of the second user are written as JSON text in one cell.
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. When the root element only wraps a list, such as <users><user/><user/></users>, the wrapper is removed so each repeated element becomes one row.
Writing CSV. Each object becomes a row. Nested objects are flattened into dotted column names such as address.city, arrays are written as JSON text in one cell, and the header is the union of keys from every row. Values containing commas, quotes or line breaks are quoted, with inner quotes doubled.
Details and limits
- Values are carried across without losing anything in ordinary data; the points above list the cases the two formats handle differently.
- If the root element only wraps one kind of child, the wrapper is removed and each child becomes a row. A document with a single record gives a header and one row.
- Attributes become columns named with an
@prefix, and child elements with their own children are flattened into dotted column names. - An element that repeats inside one record cannot be a single cell value, so it is written as JSON text.
- 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 CSV?
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 CSV do?
XML to CSV reads XML and writes it as CSV. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.
How does XML to CSV work?
Reading XML. The input is parsed with the browser's XML parser.
Are there any limits I should know about?
If the root element only wraps one kind of child, the wrapper is removed and each child becomes a row. A document with a single record gives a header and one row. Attributes become columns named with an @ prefix, and child elements with their own children are flattened into dotted column names.
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.