DevSwitch.net
Back to Tools
⇄

XML to CSV Converter

Convert XML data to CSV format

File Converters

Tip: XML should have repeating elements (like <row>) that will be converted to CSV rows.

Runs in your browser

Input XML

Convert XML to CSV in your browser

Paste XML, open an .xml file or drop it on the input window, and the CSV appears as you type. Each repeated element becomes one row, and its attributes and child elements become the columns. Copy the result or download it as a .csv file for Excel, Google Sheets or a database import.

The header row lists every column found in any row, in the order the converter first meets it. A row that lacks one of them gets an empty cell, so all rows keep the same columns.

XML to CSV example

Real output for a catalog of two books. Each <book> is a row, its id attribute is the @id column, and the price keeps its trailing zero:

catalog.xml
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="bk101">
    <title>Paper Tigers</title>
    <author>Rina Okafor</author>
    <price>12.50</price>
  </book>
  <book id="bk102">
    <title>Salt Roads</title>
    <author>Jonas Hale</author>
    <price>9.99</price>
  </book>
</catalog>
catalog.csv
@id,title,author,price
bk101,Paper Tigers,Rina Okafor,12.50
bk102,Salt Roads,Jonas Hale,9.99

Which XML element becomes a row

CSV is a flat table, so the converter first looks for the element that repeats:

  • XML

    <catalog><book/><book/></catalog>

    CSV

    The root holds one element name that repeats, so each <book> is a row.

  • XML

    <export><items><item/><item/></items></export>

    CSV

    A wrapper with a single child is passed through, so each <item> is still a row.

  • XML

    <catalog><book/></catalog>

    CSV

    With only one <book> there is one row, and the column names keep the element name: book.@id, book.title.

  • XML

    <order><id/><date/></order>

    CSV

    Different children and none repeating: the whole document is one row with a column per child.

Attributes and nested elements as columns

Inside a row, every value gets a column named after its path:

In the XMLCSV column
<book id="bk101"> @id
<title>Paper Tigers</title> title
<address><city>Oslo</city></address> address.city
<tag>a</tag><tag>b</tag> tag.0, tag.1
<price currency="EUR">12.50</price> price.@currency, price.#text

Values are copied as written, so 12.50 keeps its zero and an ID like 007 keeps its leading zeros. A value that holds a comma, a double quote or a line break is put in double quotes, with inner quotes doubled, so a spreadsheet reads it as one cell.

Need XML from a CSV file?

The CSV to XML converter turns each row into a <row> element, and an @id column back into an attribute.

XML to CSV questions

Click Open file and choose the .xml file, or drop it on the input window. The table is built straight away; Download saves it as a .csv file you can open in Excel or Google Sheets.

No element repeats where the converter looks: under the root, or under a chain of wrappers with one child each. If your records sit deeper next to other elements, paste only the part that holds them, wrapped in one root element.

Those columns come from attributes. The @ keeps an attribute apart from a child element with the same name, such as an id attribute and an <id> element.

Yes, the XML to TSV converter builds the same table with tabs between the columns.

No. Converting runs in your browser, and an opened file is read there too.