How to Convert XML to CSV (and Open It in Excel)
Lots of data arrives as XML: exports from shop and accounting software, product feeds, bank statements, sitemaps and answers from older web services. XML is great for programs but hard to read. A spreadsheet is the opposite: sort it, filter it, total a column. A CSV file is the simple bridge between the two, and every spreadsheet opens it.
This guide shows how to convert with the free XML to CSV converter: which element becomes the rows, what happens to attributes, repeated and nested elements, and how to open the result in Excel without broken accents.
What the conversion does
Each record in the XML becomes one row, and each piece of information in it becomes one column. This shop list:
<?xml version="1.0" encoding="UTF-8"?>
<shop>
<book id="bk101" lang="en">
<title>XML & JSON for Everyone</title>
<author>Ada Lovelace</author>
<price currency="EUR">29.95</price>
<tag>data</tag>
<tag>web</tag>
</book>
<book id="bk102" lang="de">
<title>Daten für alle</title>
<author>Alan Turing</author>
<price currency="EUR">24.50</price>
<tag>data</tag>
</book>
</shop>becomes this CSV:
@id,@lang,title,author,price,price/@currency,tag
bk101,en,XML & JSON for Everyone,Ada Lovelace,29.95,EUR,data; web
bk102,de,Daten für alle,Alan Turing,24.50,EUR,dataThe column names show where each value came from:
@idand@langare attributes of<book>(the values inside the tag itself).titleandauthorare child elements.price/@currencyis thecurrencyattribute of<price>, right next to the price.- The two
<tag>elements are joined in one cell:data; web.
The & in the title is turned back into a plain &, and values are copied exactly, so 24.50 keeps its zero.
How to convert XML to CSV, step by step
- Open the XML to CSV converter and paste your XML into XML input, click Open file, or drop an .xml file onto the box. Sample loads an example.
- Check One row per. It picks the repeated element on its own, which is nearly always right (more on this below).
- Choose the Separator and the other options, explained below.
- Click Convert to CSV, then Download the .csv file or Copy it.
A line under the result says what you got, such as 2 rows × 7 columns, one row per <book>. If the XML has a mistake, the converter points to its line and column instead, so you can fix it.
Choosing what becomes a row
The converter looks for elements that repeat under the same parent and suggests the top-most one: the records, not their details. For the shop above, the choices are:
Automatic: <book> (2)
shop/book (2)
shop/book/tag (3)The number in brackets is how many rows you’ll get. Automatic picks <book>, one row per book. Choosing shop/book/tag instead gives one row per tag (three rows), which is handy when the details are what you want to count. If your file holds several lists, such as customers and orders, pick the one you need here and convert the other one separately.
Repeated elements: one cell or separate columns
A record can contain the same element more than once, like the two tags of the first book. Repeated elements decides what happens:
- Join in one cell (the default) puts them together with a semicolon,
data; web, as shown above. Best for reading and filtering. - Separate columns gives each one its own numbered column. A record with fewer of them gets empty cells, and a note under the result says so:
@id,@lang,title,author,price,price/@currency,tag[1],tag[2]
bk101,en,XML & JSON for Everyone,Ada Lovelace,29.95,EUR,data,web
bk102,de,Daten für alle,Alan Turing,24.50,EUR,data,Nested and missing elements
Elements inside elements become columns named with their path, so a CSV stays flat. A record without some element simply gets empty cells in those columns:
<customers>
<customer id="7">
<name>Ada</name>
<address><city>London</city><zip>NW1</zip></address>
</customer>
<customer id="8">
<name>Alan</name>
</customer>
</customers>@id,name,address/city,address/zip
7,Ada,London,NW1
8,Alan,,Opening the CSV in Excel or Google Sheets
- Separator: many Excel versions in Europe expect a semicolon instead of a comma, and otherwise show everything in one column. Pick Semicolon under Separator in that case. Values that contain the separator are put in quotes automatically, so they stay in one cell:
@id;@lang;title;author;price;price/@currency;tag
bk101;en;XML & JSON for Everyone;Ada Lovelace;29.95;EUR;"data; web"
bk102;de;Daten für alle;Alan Turing;24.50;EUR;data- Accents: the file is saved as UTF-8. If letters like ü or é look wrong after a double-click, open the file in Excel with Data > From Text/CSV and choose 65001: Unicode (UTF-8) as the file origin. Google Sheets reads it correctly with File > Import.
- Numbers with zeros: the CSV keeps
007and24.50exactly, but spreadsheets may show them as7and24.5. When importing, set those columns to Text to keep them as they are.
Protection against spreadsheet formulas
A cell starting with =, +, - or @ can run as a formula when the CSV is opened in a spreadsheet, which is a known trick for hiding harmful formulas in exported data. With Protect against spreadsheet formulas on (the default), such values get an apostrophe in front, so =1+1 becomes '=1+1 and shows as text. The apostrophe also appears before values like phone numbers that start with +; turn the option off if the CSV goes into another program rather than a spreadsheet.
More XML tools
- XML Formatter: make the XML readable first, or explore it in the Tree view to find the records.
- XML to JSON: keep the nesting instead of flattening it into a table.
- CSV to XML: the other way round. See how to convert CSV to XML.
Is my XML 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
Can I convert XML straight to an Excel file (.xlsx)?
Convert it to CSV, open the CSV in Excel and choose File > Save As > Excel Workbook. Every spreadsheet can open a CSV, which is why it’s the format the converter writes.
Why is my CSV only one row?
Nothing in the XML repeats, so the whole document is one record. If the file really holds a list, check One row per and pick the element that should be the rows.
Can I leave out the column names?
Yes. Untick Header row and the CSV starts straight with the data, which some imports expect.