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 & 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 header | XML element |
|---|---|
full name | full_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.10would become1.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_bcontaining1;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
column2orname_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.