FormatterHQ

CSV to XML Converter

Turn CSV rows into well-formed XML. Name the root and row elements, map columns to attributes with a prefix, and rebuild nested elements from dotted headers.

Input CSV
Output XML
Ready.

How to use the CSV to XML Converter

  1. Paste CSV, upload or drop a file, use Load URL, or click Sample.
  2. Set Root element and Array item element, for example catalog and product.
  3. Prefix header names with the Attribute prefix (default @) for columns that should become attributes, and choose XML declaration and Indent.
  4. Click Convert to XML, then copy or download the document.

Convert CSV to XML with your own element names

Many import screens, feeds and older enterprise systems still expect XML, while the data you have sits in a spreadsheet. This CSV to XML converter wraps every row in an element of your choice and turns each column into a child element, producing a well-formed document with a single root that you can validate, transform or upload.

Example

A header that starts with @ marks a column as an attribute:

@sku,name,2024 sales,note
A1,Salt & pepper,120,
B2,Olive oil,85,cold pressed

With Root element set to catalog and Array item element set to product:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <product sku="A1">
    <name>Salt &amp; pepper</name>
    <_2024_sales>120</_2024_sales>
    <note/>
  </product>
  <product sku="B2">
    <name>Olive oil</name>
    <_2024_sales>85</_2024_sales>
    <note>cold pressed</note>
  </product>
</catalog>

Several things happened automatically: the ampersand was escaped, the empty note became a self-closing element, and the header 2024 sales was turned into a legal element name.

How columns become XML

  • Rows – each record becomes one item element directly under the root, in file order.
  • Columns – each header becomes a child element holding the cell text.
  • Attributes – a header beginning with the attribute prefix (@sku) becomes an attribute of the row element instead of a child. Change the prefix if your headers already use @ for something else, or clear it to write every column as an element.
  • Escaping – &, < and > in values are escaped, so a cell containing HTML or a company name like Smith & Co cannot break the document.

Element name rules

XML names are stricter than CSV headers. A name may not contain spaces, may not start with a digit, and names starting with xml are reserved. The converter repairs headers instead of failing:

CSV headerXML element
full namefull_name
2024 sales_2024_sales
price (€)price____

The same rules apply to the root and item names you type. If the receiving system expects exact names, rename the headers in the CSV first; that is easier than editing every element afterwards.

Nested elements from dotted headers

Tick Nest dotted headers and a header such as address.city produces an <address> element containing <city>:

id,name,address.city,address.zip
7,Ana,Lisbon,1100-148
<customers>
  <customer>
    <id>7</id>
    <name>Ana</name>
    <address>
      <city>Lisbon</city>
      <zip>1100-148</zip>
    </address>
  </customer>
</customers>

This is the easiest way to reproduce a structure that an XML schema or an XSLT stylesheet already expects.

Other options

  • XML declaration – adds <?xml version="1.0" encoding="UTF-8"?> at the top. Untick it when the output will be pasted into a larger document.
  • Indent – 2, 3 or 4 spaces or a tab.
  • Detect numbers & booleans – XML stores everything as text, so this only changes how numbers are written: 1.10 would become 1.1. Untick it to copy cell text exactly, which is usually what you want for version numbers and prices.
  • First row is header – if your file has no header, untick it; each value is then written as a generic item element, which is rarely useful, so adding a header row is the better fix.

Where CSV to XML conversion helps

  • Product and price feeds – shop platforms and marketplaces that import XML feeds, where the catalog is maintained in a spreadsheet.
  • Legacy integrations – ERP, banking or government systems whose upload format is an XML file with a fixed element layout.
  • Test data – realistic input for an XSLT stylesheet, an XPath query or an XML parser you are writing.
  • Content migration – moving records into a CMS that imports XML.

Troubleshooting

  • A single element named like a_b containing 1;2 – the file is separated by semicolons but the delimiter was set to comma. Choose the right delimiter or leave it on Auto-detect.
  • Invalid CSV with a record number – a quoted value never closes, or an inner quote was not doubled. Correct that record and convert again.
  • Elements named column2 or name_2 – the header row has an empty cell or a repeated name. Give every column a unique header.

After converting

Run the result through the XML validator if a partner system is strict, or tidy it further with the XML formatter. To go back from XML to rows and columns, use XML to CSV.

Privacy

The XML is built by JavaScript in your browser tab and your CSV stays on your device. It is sent to our server only when you choose Load URL or create a link with Save & Share.

Frequently asked questions

How do I make a column an XML attribute?
Start its header with the attribute prefix, which is @ by default. A column named @id becomes id="…" on each row element, while all other columns stay child elements.
Why was my header renamed in the XML?
XML element names cannot contain spaces or most punctuation and cannot begin with a digit. Invalid characters are replaced with underscores and a leading underscore is added where needed, so the document stays well-formed.
Can I generate XML without the declaration line?
Yes. Untick XML declaration and the output starts directly with the root element, which is convenient for pasting into another document.
How are empty cells written?
An empty cell produces a self-closing element for that column, so every row has the same set of child elements.

Last updated September 26, 2026

Related tools