CSV to XML
- 62 tools
- No watermark
- No daily limit
Well-formed XML from a CSV file or pasted text: one element for each row, one child element for each column, named after the column’s header. You choose what the document and each record are called. Headers are whatever somebody typed into the first row, so a header with a space in it, one starting with a digit, two columns with the same name or one with no name at all are each turned into a name XML allows, and every change is listed so nothing is renamed behind your back. Thai headers stay in Thai, because XML allows them. Nothing leaves your browser.
1 · The CSV
2 · Options
Turn this off if the first row is data.
An example, in both layouts
This CSV:
name,phone,city
Somchai Jaidee,0812345678,"Chiang Mai, Chang Khlan"
Mali Rakthai,0898765432,Phuket
with each column as a child element, the default:
<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row>
<name>Somchai Jaidee</name>
<phone>0812345678</phone>
<city>Chiang Mai, Chang Khlan</city>
</row>
<row>
<name>Mali Rakthai</name>
<phone>0898765432</phone>
<city>Phuket</city>
</row>
</rows>
and with each column as an attribute of the row:
<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row name="Somchai Jaidee" phone="0812345678" city="Chiang Mai, Chang Khlan"/>
<row name="Mali Rakthai" phone="0898765432" city="Phuket"/>
</rows>
How column headers become tag names
| Header in the CSV | Tag name in the XML |
|---|---|
first name | first_name |
2024 | _2024 |
Time: start | Time_start |
ราคา/หน่วย | ราคา_หน่วย |
xmlData | _xmlData |
ชื่อ | ชื่อ |
A space or a symbol becomes an underscore, a name that would start with a digit or with the letters xml gets one in front, and a Thai name stays Thai.
Frequently asked questions
How does a CSV become XML?
Each row becomes one element, called row unless you name it otherwise, and each value becomes a child element named after its column: a column headed email gives an element called email around each value. All the rows sit inside one document element, called rows by default, because XML must have exactly one. The declaration at the top says the file is UTF-8, which it is.
My column headers have spaces in them. Is that a problem?
Not here. An XML name cannot contain a space, cannot start with a digit, and should not contain a colon, so first name becomes first_name, 2024 becomes _2024, and Time: start becomes Time_start. Two columns both called Phone become Phone and Phone_2, and a column with no header becomes column_3. The page lists every name it changed, so you can see exactly what your XML will contain before you use it.
Can the tags be in Thai?
Yes, and they are kept that way: a column headed ชื่อ gives an element called ชื่อ. XML has allowed names in any alphabet for as long as it has existed, and every mainstream reader accepts them. A few characters that are not letters, such as ฿, are replaced, because some readers refuse them. If the system you are feeding needs English tag names, rename the headers in the first row before converting.
Child elements or attributes?
Child elements are the usual choice and what most import screens expect: one element per value, each on its own line. Attributes put a whole record on one line, as name and value pairs inside the row’s own tag, which is more compact and what some feeds and configuration formats ask for. The values are the same either way.
What happens to ampersands, angle brackets and line breaks in the data?
They are escaped, so the document stays well-formed: & is written & and < is written <. A line break inside a value is kept exactly, including the carriage return Windows puts in, which a plain XML writer loses. A handful of control characters cannot appear in XML at all, even escaped; if any are in your file they are left out and the page says how many.
Some rows have fewer columns than the header.
They are kept. A missing value is written as an empty element, and a row with more values than there are headers gets extra elements named column_4, column_5 and so on. The page counts these rows so you know to look.
Is my file uploaded?
No. Your browser reads the CSV and writes the XML. The site’s security policy sets connect-src ‘none’, so the browser blocks network requests from these pages, so nothing could be sent even if the code tried.
How large a file can it take?
Any size. The file is read a piece at a time and the XML is written a piece at a time, so a file larger than your computer’s memory is fine. The page shows the first 200 KB of the result; the download has all of it.
Can I turn the XML into JSON afterwards?
Yes. The JSON and XML page on this site reads what this writes, Thai tag names included, and there is a CSV to JSON page if JSON is where you are going anyway.