How to Convert CSV to XML

Convert a CSV into clean, well-formed XML, with each row as an element and each column as a child tag or attribute. No upload, no sign-up, free.

Updated 4 min read By CodingEagles
Free tool CSV to XML Converter Turn a CSV into clean XML, one element per row. Open tool

A system asks you to supply data as XML, but what you have is a CSV. Many feeds, legacy imports and configuration formats still expect XML, and hand-tagging rows is slow and easy to get wrong, especially once you have to escape stray ampersands and angle brackets.

The short version: paste a CSV, name the elements, and copy the XML. The CSV to XML tool runs on your device, so nothing is uploaded.

How rows turn into XML

XML wraps your data in a tree. A single root element holds one element per row, and inside each row the column values appear as child tags named after the headers. This CSV:

name,qty
Tea,5
Coffee,12

becomes:

<rows>
  <row>
    <name>Tea</name>
    <qty>5</qty>
  </row>
  <row>
    <name>Coffee</name>
    <qty>12</qty>
  </row>
</rows>

You name the root (rows above) and the per-row element (row) yourself, so the output matches whatever the receiving system expects.

Tags or attributes

There are two common ways to write each value, and you can choose. As child tags, shown above, each value sits in its own element, which is readable and easy to extend later. As attributes, the same row collapses to <row name="Tea" qty="5"/>, which is more compact. Child tags are the default because they cope better with values that contain special characters or that you may want to nest further.

Why escaping matters

XML has reserved characters. An ampersand, a less-than sign or a quote mark inside a value will break the document unless it is written as an entity, so Tea & Co has to become Tea &amp; Co. The conversion handles this for every value. It also fixes header names that are not legal XML tag names, such as one that starts with a number or contains a space, so the result always parses.

How to convert CSV to XML

Step 1: Add the CSV

Paste CSV text into the tool or drop in a file. The header row supplies the tag names.

Step 2: Set the names and style

Name the root and row elements. Choose child tags or attributes for the values.

Step 3: Copy or download

Copy the XML or download it as a file, ready for a feed, an API or an import.

If the target is a database rather than an XML consumer, the CSV to SQL tool generates INSERT statements instead. And to go from a spreadsheet to a key-value structure for an app, the Excel to JSON converter produces an array of row objects.

Frequently asked questions

How does a CSV map to XML?
Each data row becomes a row element inside a root element, and each column becomes a child tag or an attribute named after its header. A row with Name and Email columns becomes an element holding a Name tag and an Email tag, the shape most XML imports expect.
What happens to characters like & and <?
They are escaped automatically, so an ampersand becomes &amp; and an angle bracket becomes its entity, keeping the XML well-formed. Header names that are not valid XML tag names, such as one starting with a digit, are adjusted so the document still parses.
Can I use attributes instead of child tags?
Yes. Switch to the attribute style and each value becomes an attribute on the row element, giving a more compact document. Child tags are usually easier to read and extend, so they are the default.
Is my CSV uploaded?
No. The file is read and converted on your own device. Nothing is uploaded, nothing is stored, and the data never leaves your browser.

Ready to try it?

Turn a CSV into clean XML, one element per row. Free, in-browser, and 100% private — your data never leaves your device.

Open the CSV to XML Converter