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.
3 rows, 4 columns, comma delimiter.
- Some headers are not valid XML names and were renamed (see the table of names below).
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 header | Element name |
|---|---|
| first name | first_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 header | As in the header | snake_case | camelCase | PascalCase |
|---|---|---|---|---|
| first name | first_name | first_name | firstName | FirstName |
| Unit Price ($) | Unit_Price____ | unit_price | unitPrice | UnitPrice |
| 2024 sales | _2024_sales | _2024_sales | _2024Sales | _2024Sales |
| e_mail | ||||
| xmlData | xmlData | xml_data | xmlData | XmlData |
| ns:id | ns_id | ns_id | nsId | NsId |
| (empty, 3rd column) | column_3 | column_3 | column_3 | column_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 toolsCSV to JSON
Convert CSV to JSON: the first row becomes the keys, quoted commas and line breaks are kept, and numbers and booleans are detected only if you ask.
JSON to CSV
Turn JSON into CSV: an array of objects, one object or a list of values. Flatten nested objects, expand arrays into rows, then copy or download.
XML to JSON Converter
Convert XML to JSON and JSON back to XML: attributes go under @attributes, repeated elements become arrays, and an XML error shows its line and column.
YAML to JSON Converter
Convert YAML to JSON with anchors and merge keys resolved, YAML 1.2 or 1.1 typing for yes/no, and a warning for numbers JSON cannot hold.
JSON to YAML
Convert JSON to YAML in block or flow style. Text such as yes or 017 is quoted so it stays a string, and a JSON error shows its line and column.
SQL to JSON
Turn SQL INSERT statements, or a result table pasted from psql, MySQL or Markdown, into JSON. Quoted values stay strings; numbers, true and NULL get types.