World’s largest virtual agentic engineering & quality conference
This free tool allows you to convert XML data to CSV in your browser. Paste or upload XML and download a CSV file instantly. It is brought to you by TestMu AI (formerly LambdaTest), the team behind a unified software testing platform.
Paste well-formed XML with repeating record elements. Nested tags become dotted columns.
Separates CSV columns. Tab downloads as .tsv.
Converts as you type or change the delimiter.
Convert to CSV
XML and CSV are two common file formats that store and transfer data. XML is a markup language used to describe data in a hierarchical structure. CSV is a simple text format used to store tabular data. When you need to convert data from one format to another, tools are available for the job. An XML to CSV converter is an online tool that converts data in XML format to data in CSV format. The converter reads the XML file, parses it, extracts the relevant data, then formats it in CSV format, which can be saved as a new file or output to the console.
There are several reasons why you might want to convert data from XML to CSV format. These reasons include CSV files are:
If you prefer a spreadsheet, Microsoft Excel can import an XML file, flatten it into a table, and export it as CSV. The exact menu depends on your Excel version.
Open the Data tab, click From Other Sources → From XML Data Import, choose your file, and click Open. If Excel warns that "The specified XML source does not refer to a schema", click OK so Excel builds a schema from the data, then pick "XML table in existing worksheet" or "XML table in new worksheet". Finally, use Save As → "CSV (Comma delimited) (*.csv)".
Excel turns repeating elements into rows and child tags into columns. Deeply nested or irregular XML may need the Transform Data step (in Power Query) to expand nested columns first. Saving as CSV keeps only the active sheet, and in some regional settings "CSV (Comma delimited)" follows your system list separator. If you need true commas, use the CSV UTF-8 option. On a Mac, Get Data → From XML requires Excel for Microsoft 365 version 16.69 or later, and the Developer-tab XML tools are Windows-only.
For large files, automation, or batch jobs, a short script is a reliable route. Both examples below quote fields correctly and let you choose the delimiter.
The quickest path uses pandas' read_xml() function (added in pandas 1.3):
import pandas as pd
# pandas.read_xml() uses the lxml package by default (pip install lxml),
# or pass parser="etree" to use Python's built-in parser for simple XML.
df = pd.read_xml("books.xml")
df.to_csv("books.csv", index=False) # comma-delimited; quotes fields automaticallyFor more control, the standard library's xml.etree.ElementTree walks the tree while Python's csv module writes RFC 4180-compliant output. It automatically wraps any value containing a comma, quote, or line break in double quotes:
import csv
import xml.etree.ElementTree as ET
root = ET.parse("books.xml").getroot()
# One dict per record, using each direct child tag as a column.
rows = [{child.tag: child.text for child in record} for record in root]
# Header = the union of every record's tags, so ragged records stay aligned.
fieldnames = list({key: None for row in rows for key in row})
with open("books.csv", "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=fieldnames, restval="")
writer.writeheader()
writer.writerows(rows)Both write comma-delimited CSV. Pass delimiter=";" to csv.DictWriter (or sep=";" to to_csv) when you need a semicolon file.
Node has no built-in XML parser, so combine fast-xml-parser with json2csv:
// npm install fast-xml-parser @json2csv/plainjs
const fs = require("fs");
const { XMLParser } = require("fast-xml-parser");
const { Parser } = require("@json2csv/plainjs");
const data = new XMLParser().parse(fs.readFileSync("books.xml", "utf8"));
// fast-xml-parser returns an object for a single record and an array for
// many, so normalise to an array before converting. Adjust the path below.
const rows = [].concat(data.library.book);
fs.writeFileSync("books.csv", new Parser().parse(rows));Notepad++ has no built-in XML-to-CSV command, but the free XML Tools plugin adds one reliable route, and Find & Replace covers simple cases.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="/library">
<xsl:text>isbn,title,author,genre </xsl:text>
<xsl:apply-templates select="book" />
</xsl:template>
<xsl:template match="book">
<xsl:value-of select="isbn"/>,<xsl:value-of select="title"/>,<xsl:value-of select="author"/>,<xsl:value-of select="genre"/><xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>Run the transformation and save the result with a .csv extension.
For small, flat XML you can use Search → Replace with the Search mode set to "Regular expression" to turn closing-then-opening tags into commas, record boundaries into new lines, and then strip the remaining tags. This is quick but fragile. It has no understanding of XML structure, so it breaks on nested elements or on any value that itself contains a comma. For anything beyond trivial, flat data, use the XSLT method above, Excel, or a script.
The converter on this page works best with XML that has a repeating record element. Nested child tags become dot-notation columns, and attributes become their own columns. For example, this input:
<?xml version="1.0" encoding="UTF-8" ?>
<library>
<book>
<isbn>978-3-16-148410-0</isbn>
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<genre>Fiction</genre>
</book>
<book>
<isbn>978-0-14-118263-6</isbn>
<title>To Kill a Mockingbird</title>
<author>Harper Lee</author>
<genre>Historical Fiction</genre>
</book>
</library>produces this CSV, where each <book> becomes a row and each child tag becomes a column heading:
isbn,title,author,genre 978-3-16-148410-0,The Great Gatsby,F. Scott Fitzgerald,Fiction 978-0-14-118263-6,To Kill a Mockingbird,Harper Lee,Historical Fiction
If a record contains nested child elements (a tag inside a tag), this converter flattens them into dotted column names such as dimensions.width. XML attributes on a record or nested element become columns named with an @ prefix, for example @id or dimensions.@unit. For very deep or irregular trees, Excel Power Query's Transform Data step or the Python/Node scripts above give you more control over which levels become columns.
Use the Delimiter control above the Convert button to choose comma, semicolon, or tab. Semicolon suits some European spreadsheets. Tab downloads as a .tsv file. You can also set the delimiter in the Python or Node scripts if you automate the conversion.
In CSV, a comma always separates fields, so any value that itself contains a comma, a double quote, or a line break must be wrapped in double quotes, with embedded quotes doubled. This is the RFC 4180 rule. This converter applies that quoting automatically for the selected delimiter. Open the CSV in a spreadsheet to confirm the columns line up.
An XML to CSV converter is an online tool that converts data in XML format to data in CSV format.
After you create a CSV file, test it to make sure the data was formatted correctly and all information was extracted. If problems arise, you might have to adjust the conversion process or manually edit the CSV file.
XML to CSV conversion may not be suitable for all types of data, such as data that requires nested structures or complex relationships between data elements. Additionally, some formatting or metadata may be lost during the conversion process.
Did you find this page helpful?
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance