Skip to main content
CalcChef

CSV to XML

Convert CSV to XML: each row becomes a row element with one child per column, headers become valid XML names, and quoted commas and line breaks are kept. How it works

Use the CSV to XML

Up to 2,000,000 characters; drop a file on the box to load it (read as UTF-8 unless you pick another encoding). The XML declaration always says UTF-8. Nothing is uploaded.

XML Output

3 rows, 4 columns, comma delimiter.

  • Some headers are not valid XML names and were renamed (see the table of names below).
Write these columns as attributes of <row> instead of child elements

Element names

A header that is not a valid XML name is rewritten: spaces and other characters a name cannot hold become "_", "_" is put in front of a name that cannot start with its first character, an empty header becomes column_N, and a repeated name gets _2, _3.

CSV headerElement name
first namefirst_name

About the CSV to XML

Each CSV row becomes a row element with one child per column, named after the header: the header first name becomes <first_name>, and a quoted field keeps its commas. This CSV to XML converter reads RFC 4180 CSV with a comma, semicolon, tab, pipe or any other single-character delimiter, and lets you rename the root and row elements or write chosen columns as attributes. Element names can follow the header as written or be turned into snake_case, camelCase or PascalCase, and the XML can be indented or minified, with or without the XML declaration.

CSV headers and the element names they get

CSV headerAs in the headersnake_casecamelCasePascalCase
first namefirst_namefirst_namefirstNameFirstName
Unit Price ($)Unit_Price____unit_priceunitPriceUnitPrice
2024 sales_2024_sales_2024_sales_2024Sales_2024Sales
e-maile-maile_maileMailEMail
xmlDataxmlDataxml_dataxmlDataXmlData
ns:idns_idns_idnsIdNsId
(empty, 3rd column)column_3column_3column_3column_3

A name that repeats gets _2, _3: the headers name,name and an empty third header give name, name_2 and column_3.

Frequently asked questions

How do I convert CSV to XML with attributes?
Press a column’s button under “Write these columns as attributes”. With id picked, the sample’s first row becomes <row id="1"> with first_name, city and note as child elements.
What happens to commas and quotes inside a CSV field?
Quote the field, as RFC 4180 says: "Wrote the first program, in 1843" stays one value, and two quote marks inside quotes stand for one, so "Said ""machines can think""" gives Said "machines can think". A quoted field can also hold line breaks.
Why was my header renamed?
An XML name cannot hold spaces or most punctuation and cannot start with a digit. Such characters become _, a name that cannot start with its first character gets _ in front (2024 sales becomes _2024_sales), an empty header becomes column_N and a repeat gets _2. A table under the output lists every renamed header.
Which delimiter does it use?
Auto-detect picks whichever of comma, semicolon, tab and pipe appears most often in the header line outside quotes, so a;b gives semicolon. You can also pick one, or type any single character as a custom delimiter.
What if my CSV has no header row?
Untick First row is column names. Every row, the first included, is then data, and the columns are named column_1, column_2 and so on: the two lines 1,Ada and 2,Alan give two row elements, each with column_1 and column_2.
What if a row has the wrong number of fields?
The conversion stops and names the line: the CSV a,b followed by a row 1 gives “Line 2 has 1 field but the header has 2. Fix the row (a field with a delimiter or a line break must be in quotes).”

Related Tools

View all tools