Convert CSV to XML
Turn each CSV row into an XML element, with valid tag names.
- Nothing is uploaded
- Free
- No sign-up
Guide
CSV to XML: the complete guide
Last updated 3 min read
About this tool
PrivateCSV turns a CSV file into a well-formed UTF-8 XML document. Each row becomes an element (named row by default) and each column becomes a child element named after its header. Header names that are not legal XML tag names, such as “First Name” or “2024”, are fixed automatically, and special characters in values are escaped. The conversion runs in your browser, so the data stays on your device.
How to convert a CSV file to XML
- Choose the CSV file.
- Leave “First row is a header” ticked to use the column names as element names.
- Change the root and row element names if the receiving system expects specific ones, such as products and product.
- Click Convert to XML and download the file.
Example
Header names are made valid and special characters are escaped.
First Name,Age,Note
Ana,34,Likes <b> & <i><?xml version="1.0" encoding="UTF-8"?>
<rows>
<row>
<First_Name>Ana</First_Name>
<Age>34</Age>
<Note>Likes <b> & <i></Note>
</row>
</rows>When you need it
- Systems that only accept XML
- Older ERP and accounting integrations, some e-commerce feeds and many SOAP services expect XML. Exporting a spreadsheet as CSV and converting it is often the shortest route.
- Building a data feed
- Name the root and row elements to match what the receiver expects, then add attributes or namespaces afterwards if its schema requires them.
- Test data and fixtures
- Developers often need a quick XML sample built from tabular test data. Edit the rows in a spreadsheet, export CSV, convert.
How header names become valid XML tags
XML element names cannot contain spaces or most punctuation, cannot start with a digit and cannot start with “xml”. The converter replaces each run of invalid characters with one underscore and drops a trailing one, adds an underscore before names that start with a digit or “xml”, and numbers duplicates (name, name_2). Accented and non-Latin letters are allowed in XML, so “prénom” stays “prénom”. An empty header becomes column1, column2 and so on.
How values are escaped
The characters &, < and > are written as &, < and >. Control characters that XML 1.0 forbids, which sometimes arrive with copy-pasted data, are removed. Empty cells become empty elements such as <Note/>, so every row has the same structure.
Limits to know about
- Every column becomes a child element. The converter does not write attributes or namespaces.
- The output is well-formed but not validated against an XSD schema; values are written as text.
- Cells beyond the number of header columns are dropped.
- Files are read as UTF-8, and the XML is written as UTF-8.
Frequently asked questions
Can Excel convert CSV to XML?
Only through an XML map. Excel needs an XML schema mapped to your columns on the Developer tab before it can export XML. Without a schema, converting the CSV here is faster.
How are column names turned into XML tags?
Invalid characters become “_”, names that start with a digit or “xml” get a “_” prefix, and duplicates get a number: “First Name” becomes First_Name and a second “id” column becomes id_2.
What if my CSV file has no header row?
Untick “First row is a header” and the child elements are named column1, column2 and so on. The first row is then converted like any other row.
Can I choose the element names?
Yes. The root element is rows and each record is row by default; change both before converting. Names must be valid XML names, and the form tells you if one is not.
Is the output valid XML?
It is well-formed UTF-8 XML with an XML declaration, a single root element and escaped values, so any XML parser can read it. Whether it matches a particular schema depends on the element names you choose.
Related tools
Go further
Your files never leave your device
PrivateCSV runs every tool inside your browser. No upload, no account, nothing to install.