What CSV to XML does
CSV to XML reads CSV and writes it as XML. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.
CSV to XML examples
The built-in sample
Input
id,name,city
1,Ada,London
2,Lin,BengaluruOutput
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>
<id>1</id>
<name>Ada</name>
<city>London</city>
</item>
<item>
<id>2</id>
<name>Lin</name>
<city>Bengaluru</city>
</item>
</root>This is the input that the Load sample button fills in.
Rows become item elements
Input
id,name,note
1,"Lovelace, Ada","said ""hi"""
2,LinOutput
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>
<id>1</id>
<name>Lovelace, Ada</name>
<note>said "hi"</note>
</item>
<item>
<id>2</id>
<name>Lin</name>
<note></note>
</item>
</root>Each row is an item element inside root, with one child element per column. The quotes around hi are written as ".
Each output was produced by running this tool on the input above it.
How it works
Reading CSV. The first row is the header. Fields can be quoted to contain commas, line breaks and doubled quotes (""), following RFC 4180. Every following row becomes an object; all values are strings, and a row with fewer fields than the header is padded with empty strings.
Writing XML. Each key becomes an element and each array item repeats its element. Keys starting with @ become attributes and #text becomes text content. Keys that are not valid XML names are written as item. A single top-level key becomes the root element; anything else, including a top-level array, is wrapped in one root element so the output is always well-formed. Special characters are escaped.
Details and limits
- Values are carried across without losing anything in ordinary data; the points above list the cases the two formats handle differently.
- A header that is not a valid XML name (it contains a space, or starts with a digit) is written as
item, so rename such columns before converting if you need to tell them apart. - The wrapper names
rootanditemare fixed. - An empty field gives an element with an empty text,
<note></note>. - Input that is not valid CSV stops the tool, and the status line shows where the problem is. The CSV to JSON page lists the usual causes.
Questions
Is my data uploaded when I use CSV to XML?
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 CSV to XML do?
CSV to XML reads CSV and writes it as XML. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.
Are there any limits I should know about?
A header that is not a valid XML name (it contains a space, or starts with a digit) is written as item, so rename such columns before converting if you need to tell them apart. The wrapper names root and item are fixed.
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.