PrivateCSV

Convert XML to CSV

Turn repeated XML elements into CSV rows, with nested fields as columns.

XML file

  • Nothing is uploaded
  • Free
  • No sign-up

Guide

XML to CSV: the complete guide

Last updated 4 min read

About this tool

PrivateCSV converts an XML file to CSV by finding the element that repeats, such as <item>, <product> or <record>, and writing one row for each. Child elements and attributes become columns named by their path, so the result opens directly in Excel, Google Sheets or a database tool. The XML is read as a stream, which keeps large files manageable, and it never leaves your device.

How to check that your file is never uploaded

How to convert XML to CSV

  1. Choose the XML file.
  2. Leave “Row element” empty to let the tool find the repeated element, or type its name (for example product) to choose it yourself.
  3. Keep “Excel-compatible” ticked if you will open the CSV in Excel; untick it for a database or script. Click Convert to CSV. The result tells you which element became the rows.
  4. Download the CSV and open it in Excel, Google Sheets or your database tool.

Example

Each <book> becomes a row; attributes start with @.

catalog.xml
<catalog>
  <book id="b1">
    <title>Dune</title>
    <price currency="USD">9.99</price>
  </book>
  <book id="b2">
    <title>Emma</title>
    <price currency="GBP">7.50</price>
  </book>
</catalog>
catalog.csv
@id,title,price/@currency,price
b1,Dune,USD,9.99
b2,Emma,GBP,7.50

When you need it

Product feeds and catalogs
Shopping feeds, supplier catalogs and marketplace exports are often XML. As CSV you can review prices and stock in a spreadsheet, or prepare an import for a shop that only accepts CSV.
Data from APIs, ERPs and open-data portals
SOAP services, accounting and ERP systems, and many public data portals deliver XML. CSV is easier to filter, chart and load into SQL.
Getting XML into a spreadsheet quickly
Excel can open XML through Power Query, but nested elements must be expanded column by column. A CSV opens in one step in Excel, Google Sheets, LibreOffice and Numbers.

How XML becomes rows and columns

  • Rows: the tool counts every element path and picks the shallowest one that repeats, such as catalog/book; ties go to the most frequent. Type a name in “Row element” to override it.
  • Columns: child elements become columns named by their path inside the row, such as title, or address/city for deeper nesting.
  • Attributes: they become columns starting with @, such as @id, or price/@currency for an attribute of a child element.
  • Repeated fields: when one row contains the same element several times, such as multiple <tag> elements, the values are joined with “; ” in one cell.
  • Text: CDATA sections are read as ordinary text, and whitespace around values is trimmed.

Large XML files

The file is read twice as a stream. The first pass finds the row element and every column name; the second writes the CSV. The parser holds only the current row at a time, never the whole document, and the encoding declared in the XML header (UTF-8, ISO-8859-1 and others) is respected. We test the converter with a 120,000-record file.

Limits to know about

  • Namespaces are not resolved: prefixed names such as g:price are kept as they are in the column names.
  • One kind of row per conversion. If a file holds several lists, such as customers and orders, convert it once per list using “Row element”.
  • Lists nested inside a row are joined into single cells rather than turned into extra rows or a second table.
  • The XML must be well-formed. If it is not, the error message gives the line and column of the problem.
  • The CSV is UTF-8. “Excel-compatible” (on by default) adds a byte order mark so Excel displays accented letters correctly; a few databases and scripts read that mark as part of the first column name, so untick it for them.

Frequently asked questions

How do I convert an XML file to CSV?

Choose the file and click Convert to CSV. The tool finds the repeated element that represents a record, writes one row per record and one column per field, and gives you a CSV to download.

How do I open an XML file in Excel?

Excel's Data > Get Data > From File > From XML loads the file into Power Query, where you expand nested columns step by step. For a list of records it is usually quicker to convert the XML to CSV here and open the CSV, which also works in Google Sheets and LibreOffice.

Which element becomes a row?

The shallowest element that repeats, for example <book> inside <catalog>. If the guess is wrong, for instance because a header block also repeats, type the right element name in “Row element”.

What happens to attributes and nested elements?

Nested elements become columns named by their path, such as address/city. Attributes become columns starting with @, such as @id. If a field occurs several times in one record, its values are joined with a semicolon.

Does it work with large XML files?

Yes. The XML is streamed instead of loaded as a whole document, so the practical limit is the size of the CSV your device can hold, not the size of the XML. We test it with a file of 120,000 records.

Related tools

Go further

Your files never leave your device

PrivateCSV runs every tool inside your browser. No upload, no account, nothing to install.