How to Convert CSV to XML (Excel and Google Sheets Too)
Spreadsheets are where most data starts: product lists, price lists, contacts, orders. But many systems, such as shop and ERP imports, product feeds, publishing tools and older business software, expect XML. Converting the sheet to CSV and the CSV to XML bridges the gap without retyping anything.
This guide shows how to do it with the free CSV to XML converter, which options to choose, and how to avoid the CSV problems that most often break a conversion.
What the conversion does
Each row becomes one record element, each column one field inside it, all wrapped in a single root element:
id,title,author,price,in stock
bk101,"XML & JSON for Everyone",Ada Lovelace,29.95,true
bk102,Daten für alle,Alan Turing,24.50,false<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<id>bk101</id>
<title>XML & JSON for Everyone</title>
<author>Ada Lovelace</author>
<price>29.95</price>
<in_stock>true</in_stock>
</book>
<book>
<id>bk102</id>
<title>Daten für alle</title>
<author>Alan Turing</author>
<price>24.50</price>
<in_stock>false</in_stock>
</book>
</books>The column headings become the element names. The & in the first title is escaped as &, the comma inside the quoted title stays part of the value, and the heading “in stock”, which can’t be an XML name because of the space, becomes in_stock. A note under the result lists every name that was changed.
How to convert CSV to XML, step by step
- Open CSV to XML and paste your CSV into CSV input, click Open file, or drop a .csv file onto the box. Sample loads three books like the ones above.
- Check the line under the box, such as ✓ CSV with 5 columns and 3 rows. If the numbers look wrong, the separator or a quote is probably the problem (see below).
- Name the Root element and the Record element, and choose how values are written under Values as.
- Click Convert to XML, then download the .xml file or copy it.
Choosing good element names
The defaults are records and record, but names that describe your data are easier to work with: books and book, products and product, contacts and contact. A plural root with a singular record is the usual style. If the system you import into expects specific names, use exactly those, including upper and lower case.
XML names may contain letters, digits, -, _ and ., must start with a letter or _, and can’t contain spaces. The converter tells you if a name you typed can’t be used.
Column headings follow the same rules, so they’re adjusted automatically: spaces and other characters become _, and a heading that starts with a digit gets a _ in front. If you want specific names, rename the columns in the spreadsheet first. With First row has column names unticked, the columns are simply called column1, column2 and so on.
Child elements or attributes?
With Values as set to Attributes, the same two rows become one compact element each:
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book id="bk101" title="XML & JSON for Everyone" author="Ada Lovelace" price="29.95" in_stock="true"/>
<book id="bk102" title="Daten für alle" author="Alan Turing" price="24.50" in_stock="false"/>
</books>Child elements (the default) are the most common, read well and suit long text. Attributes give shorter files and are what some imports and configuration formats expect. When in doubt, check an example file from the system you’re feeding.
Empty cells
By default an empty cell is kept as an empty element, so every record has the same fields:
<contact>
<id>1</id>
<name>Ada</name>
<phone/>
</contact>Tick Leave out empty cells to skip them instead:
<contact>
<id>1</id>
<name>Ada</name>
</contact>Keep them when the receiving system expects every field; leave them out to get smaller files where missing means “not set”.
Avoiding CSV problems
- Separator: Automatic recognises commas, semicolons, tabs and pipes. Spreadsheets in many European countries save CSV with semicolons; that’s detected too.
- Quotes: a value that contains the separator, a quote or a line break must be in double quotes, with inner quotes doubled (
"He said ""hi"""). Excel and Google Sheets do this for you. A quote that’s never closed is reported with its line and column. - Accents: in Excel, save as CSV UTF-8 (Comma delimited) so letters like ü and é survive. In Google Sheets, File › Download › Comma-separated values is already UTF-8.
- Uneven rows: if some rows have fewer values than there are columns, the missing ones are written as empty and a note tells you how many rows were affected.
Good to know
Values are copied exactly as they are in the CSV, so 24.50 stays 24.50 and 007 keeps its zeros. Each row becomes one flat record; if you need nested XML, such as an address inside a customer, build it from JSON with JSON to XML instead.
More XML tools
- XML Formatter: check the result, or explore it in the Tree view.
- XML Validator: check it against the XSD schema of the system you import into.
- XML to CSV: the other way round. See also how to convert JSON to CSV.
Is my CSV uploaded?
No. The conversion runs in your browser, so your data never leaves your device. Our server only records that one conversion happened, for the daily limit.
Frequently asked questions
How do I convert an Excel file to XML?
Save the sheet as CSV (File › Save As › CSV UTF-8), open that file in CSV to XML and convert it.
Can I convert the XML back to CSV?
Yes, with XML to CSV. It finds the repeated record element and makes one row of each.
Why was a column renamed?
Its heading contained a space or another character that XML names can’t have, or started with a digit. The note under the result shows the old and new names.